ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2024-08-03 06:15:10
Exec Total Coverage
Lines: 1370 5638 24.3%
Functions: 49 105 46.7%
Branches: 591 2869 20.6%

Line Branch Exec Source
1 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
2
3 //glibc 2.28 and later require this: -Z
4 #ifdef __GNUG__
5 #define ALLEGRO_NO_FIX_ALIASES
6 #endif
7
8 #include "base/qrs.h"
9 #include "base/dmap.h"
10 #include "base/zc_alleg.h"
11 #include "zc/script_drawing.h"
12 #include "zc/rendertarget.h"
13 #include "zc/maps.h"
14 #include "tiles.h"
15 #include "zc/zelda.h"
16 #include "zc/ffscript.h"
17 #include "base/util.h"
18 #include "subscr.h"
19 #include "drawing.h"
20 #include "base/mapscr.h"
21 #include "base/misctypes.h"
22 using namespace util;
23 extern FFScript FFCore;
24 extern ZModule zcm;
25 extern refInfo *ri;
26 extern script_bitmaps scb;
27 #include <stdio.h>
28 #include <fstream>
29
30 #define DegtoFix(d) ((d)*0.7111111111111)
31 #define RadtoFix(d) ((d)*40.743665431525)
32
33 inline double sd_log2( double n )
34 {
35 // log(n)/log(2) is log2.
36 double v = log( (double)n ) / log( (double)2 );
37 return v;
38 }
39
40 inline bool isPowerOfTwo(int32_t n)
41 {
42 if(n==0)
43 return false;
44
45 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
46 }
47
48
49
50 template<class T> inline
51 241609 fixed degrees_to_fixed(T d)
52 {
53 241609 return ftofix(DegtoFix(d));
54 }
55 template<class T> inline
56 fixed radians_to_fixed(T d)
57 {
58 return ftofix(RadtoFix(d));
59 }
60
61 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
62
63 class TileHelper
64 {
65 public:
66
67 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
68 {
69 // Past the end of the tile page?
70
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
71 {
72 byte w2=(tile+w)%TILES_PER_ROW;
73 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
74 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
75 return;
76 }
77
78
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
79 {
80 case 1:
81 for(int32_t j=0; j<h; j++)
82 for(int32_t k=w-1; k>=0; k--)
83 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
84
85 break;
86
87 case 2:
88 for(int32_t j=h-1; j>=0; j--)
89 for(int32_t k=0; k<w; k++)
90 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
91
92 break;
93
94 case 3:
95 for(int32_t j=h-1; j>=0; j--)
96 for(int32_t k=w-1; k>=0; k--)
97 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
98
99 break;
100
101 46094 case 0:
102 default:
103
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
104
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
105 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
106
107 46094 break;
108 }
109 46094 }
110
111 3800537 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
112 {
113 3800537 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
114 3800537 }
115
116 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
117 {
118 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
119 {
120 byte w2=(tile+w)%TILES_PER_ROW;
121 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
122 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
123 return;
124 }
125
126 switch(flip)
127 {
128 case 1:
129 for(int32_t j=0; j<h; j++)
130 for(int32_t k=w-1; k>=0; k--)
131 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
132
133 break;
134
135 case 2:
136 for(int32_t j=h-1; j>=0; j--)
137 for(int32_t k=0; k<w; k++)
138 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
139
140 break;
141
142 case 3:
143 for(int32_t j=h-1; j>=0; j--)
144 for(int32_t k=w-1; k>=0; k--)
145 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
146
147 break;
148
149 default:
150 for(int32_t j=0; j<h; j++)
151 for(int32_t k=0; k<w; k++)
152 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
153
154 break;
155 }
156 }
157
158 283426 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
159 {
160
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 283426 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
283426 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
161 {
162 byte w2=(tile+w)%TILES_PER_ROW;
163 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
164 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
165 return;
166 }
167
168
1/4
✓ Branch 0 taken 283426 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
283426 switch(flip)
169 {
170 case 1:
171 for(int32_t j=0; j<h; j++)
172 for(int32_t k=w-1; k>=0; k--)
173 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
174
175 break;
176
177 case 2:
178 for(int32_t j=h-1; j>=0; j--)
179 for(int32_t k=0; k<w; k++)
180 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
181
182 break;
183
184 case 3:
185 for(int32_t j=h-1; j>=0; j--)
186 for(int32_t k=w-1; k>=0; k--)
187 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
188
189 break;
190
191 default:
192
2/2
✓ Branch 0 taken 1664044 times.
✓ Branch 1 taken 283426 times.
1947470 for(int32_t j=0; j<h; j++)
193
2/2
✓ Branch 0 taken 23537785 times.
✓ Branch 1 taken 1664044 times.
25201829 for(int32_t k=0; k<w; k++)
194 25201829 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
195
196 283426 break;
197 }
198 283426 }
199
200 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
201 {
202 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
203 {
204 byte w2=(tile+w)%TILES_PER_ROW;
205 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
206 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
207 return;
208 }
209
210 switch(flip)
211 {
212 case 1:
213 for(int32_t j=0; j<h; j++)
214 for(int32_t k=w-1; k>=0; k--)
215 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
216
217 break;
218
219 case 2:
220 for(int32_t j=h-1; j>=0; j--)
221 for(int32_t k=0; k<w; k++)
222 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
223
224 break;
225
226 case 3:
227 for(int32_t j=h-1; j>=0; j--)
228 for(int32_t k=w-1; k>=0; k--)
229 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
230
231 break;
232
233 default:
234 for(int32_t j=0; j<h; j++)
235 for(int32_t k=0; k<w; k++)
236 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
237
238 break;
239 }
240 }
241 };
242
243
244
245
246 2356005 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
247 {
248 //sdci[1]=layer
249 //sdci[2]=x
250 //sdci[3]=y
251 //sdci[4]=x2
252 //sdci[5]=y2
253 //sdci[6]=color
254 //sdci[7]=scale factor
255 //sdci[8]=rotation anchor x
256 //sdci[9]=rotation anchor y
257 //sdci[10]=rotation angle
258 //sdci[11]=fill
259 //sdci[12]=opacity
260
1/2
✓ Branch 0 taken 2356005 times.
✗ Branch 1 not taken.
2356005 if(sdci[7]==0) //scale
261 {
262 return;
263 }
264
265 2356005 int32_t x1=sdci[2]/10000;
266 2356005 int32_t y1=sdci[3]/10000;
267 2356005 int32_t x2=sdci[4]/10000;
268 2356005 int32_t y2=sdci[5]/10000;
269
270
1/2
✓ Branch 0 taken 2356005 times.
✗ Branch 1 not taken.
2356005 if(x1>x2)
271 {
272 zc_swap(x1,x2);
273 }
274
275
2/2
✓ Branch 0 taken 2336489 times.
✓ Branch 1 taken 19516 times.
2356005 if(y1>y2)
276 {
277 19516 zc_swap(y1,y2);
278 19516 }
279
280
2/2
✓ Branch 0 taken 2354328 times.
✓ Branch 1 taken 1677 times.
2356005 if(sdci[7] != 10000)
281 {
282 1677 int32_t w=x2-x1+1;
283 1677 int32_t h=y2-y1+1;
284 1677 int32_t w2=(w*sdci[7])/10000;
285 1677 int32_t h2=(h*sdci[7])/10000;
286 1677 x1=x1-((w2-w)/2);
287 1677 x2=x2+((w2-w)/2);
288 1677 y1=y1-((h2-h)/2);
289 1677 y2=y2+((h2-h)/2);
290 1677 }
291
292 2356005 int32_t color=sdci[6]/10000;
293
294
2/2
✓ Branch 0 taken 2319526 times.
✓ Branch 1 taken 36479 times.
2356005 if(sdci[12]/10000<=127) //translucent
295 {
296 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
297 36479 }
298
299
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2273945 times.
2356005 if(sdci[10]==0) //no rotation
300 {
301
2/2
✓ Branch 0 taken 731517 times.
✓ Branch 1 taken 1542428 times.
2273945 if(sdci[11]) //filled
302 {
303 1542428 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
304 1542428 }
305 else //outline
306 {
307 731517 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
308 }
309 2273945 }
310 else //rotate
311 {
312 int32_t xy[16];
313 82060 int32_t rx=sdci[8]/10000;
314 82060 int32_t ry=sdci[9]/10000;
315 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
316 82060 fixed ra2=itofix(sdci[10]/10000);
317 82060 fixed ra=ra1+ra2;
318 82060 ra = (ra/360)*256;
319
320 82060 fixed fcosa = fixcos(ra);
321 82060 fixed fsina = fixsin(ra);
322
323 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
324 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
325 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
326 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
327 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
328 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
329 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
330 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
331 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
332 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
333 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
334 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
335 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
336 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
337 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
338 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
339
340
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
341 {
342 82060 polygon(bmp, 4, xy, color);
343 82060 }
344 else //outline
345 {
346 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
347 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
348 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
349 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
350 }
351 }
352
353 2356005 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
354 2356005 }
355
356 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
357 {
358 //sdci[1]=layer
359 //sdci[2]=x
360 //sdci[3]=y
361 //sdci[4]=tile
362 //sdci[5]=cset
363 //sdci[6]=width
364 //sdci[7]=height
365 //sdci[8]=overlay
366 //sdci[9]=opacity
367
368 int32_t x=sdci[2]/10000;
369 int32_t y=sdci[3]/10000;
370
371 int32_t tile=sdci[4]/10000;
372 int32_t cs=sdci[5]/10000;
373 int32_t w=sdci[6]/10000;
374 int32_t h=sdci[7]/10000;
375 bool overlay=sdci[8];
376 bool trans=(sdci[9]/10000<=127);
377
378 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
379 }
380
381
382
383 1130854 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
384 {
385 //sdci[1]=layer
386 //sdci[2]=x
387 //sdci[3]=y
388 //sdci[4]=radius
389 //sdci[5]=color
390 //sdci[6]=scale factor
391 //sdci[7]=rotation anchor x
392 //sdci[8]=rotation anchor y
393 //sdci[9]=rotation angle
394 //sdci[10]=fill
395 //sdci[11]=opacity
396
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6]==0) //scale
397 {
398 return;
399 }
400
401 1130854 int32_t x1=sdci[2]/10000;
402 1130854 int32_t y1=sdci[3]/10000;
403 1130854 qword r=sdci[4];
404
405
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6] != 10000)
406 {
407 r*=sdci[6];
408 r/=10000;
409 }
410
411 1130854 r/=10000;
412 1130854 int32_t color=sdci[5]/10000;
413
414
2/2
✓ Branch 0 taken 959832 times.
✓ Branch 1 taken 171022 times.
1130854 if(sdci[11]/10000<=127) //translucent
415 {
416 171022 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
417 171022 }
418
419
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1072279 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1130854 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
420 {
421 int32_t xy[2];
422 57231 int32_t rx=sdci[7]/10000;
423 57231 int32_t ry=sdci[8]/10000;
424 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
425 57231 fixed ra2=itofix(sdci[9]/10000);
426 57231 fixed ra=ra1+ra2;
427 57231 ra = (ra/360)*256;
428
429 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
430 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
431 57231 x1=xy[0];
432 57231 y1=xy[1];
433 57231 }
434
435
2/2
✓ Branch 0 taken 1113840 times.
✓ Branch 1 taken 17014 times.
1130854 if(sdci[10]) //filled
436 {
437 1113840 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
438 1113840 }
439 else //outline
440 {
441 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
442 }
443
444 1130854 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
445 1130854 }
446
447
448 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
449 {
450 //sdci[1]=layer
451 //sdci[2]=x
452 //sdci[3]=y
453 //sdci[4]=radius
454 //sdci[5]=start angle
455 //sdci[6]=end angle
456 //sdci[7]=color
457 //sdci[8]=scale factor
458 //sdci[9]=rotation anchor x
459 //sdci[10]=rotation anchor y
460 //sdci[11]=rotation angle
461 //sdci[12]=closed
462 //sdci[13]=fill
463 //sdci[14]=opacity
464
465 if(sdci[8]==0) //scale
466 {
467 return;
468 }
469
470 int32_t cx=sdci[2]/10000;
471 int32_t cy=sdci[3]/10000;
472 qword r=sdci[4];
473
474 if(sdci[8] != 10000)
475 {
476 r*=sdci[8];
477 r/=10000;
478 }
479
480 r/=10000;
481
482 int32_t color=sdci[7]/10000;
483
484 fixed ra1=itofix(sdci[11]%10000)/10000;
485 fixed ra2=itofix(sdci[11]/10000);
486 fixed ra=ra1+ra2;
487 ra = (ra/360)*256;
488
489
490 fixed a1=itofix(sdci[5]%10000)/10000;
491 fixed a2=itofix(sdci[5]/10000);
492 fixed sa=a1+a2;
493 sa = (sa/360)*256;
494
495 a1=itofix(sdci[6]%10000)/10000;
496 a2=itofix(sdci[6]/10000);
497 fixed ea=a1+a2;
498 ea = (ea/360)*256;
499
500 if(sdci[11]!=0) //rotation
501 {
502 int32_t rx=sdci[9]/10000;
503 int32_t ry=sdci[10]/10000;
504
505 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
506 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
507 ea-=ra;
508 sa-=ra;
509 }
510
511 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
512 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
513
514 if(sdci[12]) //closed
515 {
516 if(sdci[13]) //filled
517 {
518 clear_bitmap(prim_bmp);
519 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
520 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
521 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
522 int fillx = zc_max(0,fx)+xoffset;
523 int filly = zc_max(0,fy)+yoffset;
524 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
525 floodfill(prim_bmp, fillx, filly, color);
526
527 if(sdci[14]/10000<=127) //translucent
528 {
529 draw_trans_sprite(bmp, prim_bmp, 0,0);
530 }
531 else
532 {
533 draw_sprite(bmp, prim_bmp, 0,0);
534 }
535 }
536 else
537 {
538 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
539 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
540 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
541 }
542 }
543 else
544 {
545 if(sdci[14]/10000<=127) //translucent
546 {
547 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
548 }
549
550 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
551 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
552 }
553 }
554
555
556 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
557 {
558 //sdci[1]=layer
559 //sdci[2]=x
560 //sdci[3]=y
561 //sdci[4]=radiusx
562 //sdci[5]=radiusy
563 //sdci[6]=color
564 //sdci[7]=scale factor
565 //sdci[8]=rotation anchor x
566 //sdci[9]=rotation anchor y
567 //sdci[10]=rotation angle
568 //sdci[11]=fill
569 //sdci[12]=opacity
570
571
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
572 {
573 return;
574 }
575
576 1850 int32_t x1=sdci[2]/10000;
577 1850 int32_t y1=sdci[3]/10000;
578 1850 int32_t radx=sdci[4]/10000;
579 1850 radx*=sdci[7]/10000;
580 1850 int32_t rady=sdci[5]/10000;
581 1850 rady*=sdci[7]/10000;
582 1850 int32_t color=sdci[6]/10000;
583 1850 float rotation = sdci[10]/10000;
584
585 1850 int32_t rx=sdci[8]/10000;
586 1850 int32_t ry=sdci[9]/10000;
587 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
588 1850 fixed ra2=itofix(sdci[10]/10000);
589 1850 fixed ra=ra1+ra2;
590 1850 ra = (ra/360)*256;
591
592 int32_t xy[2];
593 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
594 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
595 1850 x1=xy[0];
596 1850 y1=xy[1];
597
598
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
599
600 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
601
602
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
603 {
604
605
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
606 {
607 1024 clear_bitmap(prim_bmp);
608
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
609 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
610 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
611 1024 }
612 else // no opacity
613 {
614
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
615 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
616 }
617 1630 }
618 else //not filled
619 {
620
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
621 {
622 14 clear_bitmap(prim_bmp);
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
624 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
625 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
626 14 }
627 else // no opacity
628 {
629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
630 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
631 }
632 }
633
634 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
635 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
636 // the ellipse, but it shouldn't be used anyway.
637
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
638 {
639 // This is very slow, so check the smallest possible square
640 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
641 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
642
643 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
644 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
645 if(getpixel(bmp, x, y)==255)
646 putpixel(bmp, x, y, 0);
647 }
648
649 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
650 1850 }
651
652
653 2349855 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
654 {
655 //sdci[1]=layer
656 //sdci[2]=x
657 //sdci[3]=y
658 //sdci[4]=x2
659 //sdci[5]=y2
660 //sdci[6]=color
661 //sdci[7]=scale factor
662 //sdci[8]=rotation anchor x
663 //sdci[9]=rotation anchor y
664 //sdci[10]=rotation angle
665 //sdci[11]=opacity
666
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[7]==0) //scale
667 {
668 return;
669 }
670
671 2349855 int32_t x1=sdci[2]/10000;
672 2349855 int32_t y1=sdci[3]/10000;
673 2349855 int32_t x2=sdci[4]/10000;
674 2349855 int32_t y2=sdci[5]/10000;
675
676
2/2
✓ Branch 0 taken 1901533 times.
✓ Branch 1 taken 448322 times.
2349855 if(sdci[7] != 10000)
677 {
678 448322 int32_t w=x2-x1+1;
679 448322 int32_t h=y2-y1+1;
680 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
681 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
682 448322 x1=x1-((w2-w)/2);
683 448322 x2=x2+((w2-w)/2);
684 448322 y1=y1-((h2-h)/2);
685 448322 y2=y2+((h2-h)/2);
686 448322 }
687
688 2349855 int32_t color=sdci[6]/10000;
689
690
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[11]/10000<=127) //translucent
691 {
692 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
693 }
694
695
2/2
✓ Branch 0 taken 937839 times.
✓ Branch 1 taken 1412016 times.
2349855 if(sdci[10]!=0) //rotation
696 {
697 int32_t xy[4];
698 1412016 int32_t rx=sdci[8]/10000;
699 1412016 int32_t ry=sdci[9]/10000;
700 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
701 1412016 fixed ra2=itofix(sdci[10]/10000);
702 1412016 fixed ra=ra1+ra2;
703
704 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
705 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
706 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
707 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
708 1412016 x1=xy[0];
709 1412016 y1=xy[1];
710 1412016 x2=xy[2];
711 1412016 y2=xy[3];
712 1412016 }
713
714 2349855 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
715 2349855 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
716 2349855 }
717
718 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
719 {
720 //sdci[1]=layer
721 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
722
723 //sdci[2]=x
724 //sdci[3]=y
725 //sdci[4]=x2
726 //sdci[5]=y2
727 //sdci[6]=color
728 //sdci[7]=scale factor
729 //sdci[8]=rotation anchor x
730 //sdci[9]=rotation anchor y
731 //sdci[10]=rotation angle
732 //sdci[11]=opacity
733 //if(sdci[7]==0) //scale
734 //{
735 // return;
736 //}
737
738 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
739
740 if(!v_ptr)
741 {
742 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
743 return;
744 }
745
746 std::vector<int32_t> &v = *v_ptr;
747
748 if(v.empty())
749 return;
750 //Z_scripterrlog("PutPixels reached line %d\n", 983);
751
752 int32_t* pos = &v[0];
753 int32_t sz = v.size();
754
755 for ( int32_t q = 0; q < sz; q+=10 )
756 {
757
758 int32_t x1 = v.at(q);
759 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
760 int32_t y1 = v.at(q+1);
761 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
762 int32_t x2 = v.at(q+2);
763 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
764 int32_t y2 = v.at(q+3);
765 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
766 int32_t color = v.at(q+4);
767 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
768 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
769 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
770
771 if( v.at(q+5) != 10000)
772 {
773 int32_t w=x2-x1+1;
774 int32_t h=y2-y1+1;
775 int32_t w2=int32_t(w*((double)v.at(q+5)));
776 int32_t h2=int32_t(h*((double)v.at(q+5)));
777 x1=x1-((w2-w)/2);
778 x2=x2+((w2-w)/2);
779 y1=y1-((h2-h)/2);
780 y2=y2+((h2-h)/2);
781 }
782
783
784 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
785 if(v.at(q+9) <= 127) //translucent
786 {
787 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
788 }
789 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
790 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
791 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
792 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
793 if( v.at(q+8) !=0 ) //rotation
794 {
795 int32_t xy[4];
796
797 int32_t rx = v.at(q+6);
798
799 int32_t ry = v.at(q+7);
800
801 fixed ra1=itofix(v.at(q+8) % 1);
802 fixed ra2=itofix(v.at(q+8));
803 fixed ra=ra1+ra2;
804
805 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
806 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
807 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
808 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
809 x1=xy[0];
810 y1=xy[1];
811 x2=xy[2];
812 y2=xy[3];
813 }
814 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
815 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
816 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
817 }
818 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
819 }
820
821 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
822 {
823 //sdci[1]=layer
824 //sdci[2]=point count
825 //sdci[3]array[]
826 //sdci[4] = colour
827 //sdci[5] = opacity
828
829 int32_t col = sdci[4]/10000;
830 int32_t op = sdci[5]/10000;
831
832 //bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
833 //Z_scripterrlog("Broken offset rule for Polygon() is: %s\n", brokenOffset ? "ON" : "OFF");
834 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
835
836 if(!v_ptr)
837 {
838 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
839 return;
840 }
841
842 std::vector<int32_t> &v = *v_ptr;
843
844 if(v.empty())
845 return;
846 //Z_scripterrlog("PutPixels reached line %d\n", 983);
847
848 int32_t* pos = &v[0];
849 int32_t sz = v.size();
850 int32_t numpoints = (sdci[2]/10000);
851 if(sz & 1) --sz; //even amount only
852 if(numpoints > sz/2) //cap to array
853 numpoints = sz/2;
854 if(numpoints < 1)
855 return; //Don't draw 0 or negative point count
856
857 //Fix the draw Y offset. -Z 20th June, 2019
858 for ( int32_t q = 1; q < sz; q+=2 )
859 {
860 pos[q] += yoffset;
861 }
862 if(op <= 127) //translucent
863 {
864 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
865 }
866 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
867
868 polygon(bmp, numpoints, (int32_t*)pos, col);
869 //polygon(bmp, (sdci[2]/10000), &v, col);
870 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
871 }
872
873 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
874 {
875 //sdci[1]=layer
876 //sdci[2]=point count
877 //sdci[3]array[]
878 //sdci[4] = colour
879 //sdci[5] = opacity
880
881 int32_t col = sdci[4]/10000;
882 int32_t op = sdci[5]/10000;
883
884 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
885 {
886 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
887 return;
888 }
889 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
890 if ( refbmp == NULL ) return;
891
892 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
893
894 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
895
896 if(!v_ptr)
897 {
898 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
899 return;
900 }
901
902 std::vector<int32_t> &v = *v_ptr;
903
904 if(v.empty())
905 return;
906 //Z_scripterrlog("PutPixels reached line %d\n", 983);
907
908 int32_t* pos = &v[0];
909 int32_t sz = v.size();
910 int32_t numpoints = (sdci[2]/10000);
911 if(sz & 1) --sz; //even amount only
912 if(numpoints > sz/2) //cap to array
913 numpoints = sz/2;
914 if(numpoints < 1)
915 return; //Don't draw 0 or negative point count
916
917 //Fix the draw Y offset. -Z 20th June, 2019
918 for ( int32_t q = 1; q < sz; q+=2 )
919 {
920 pos[q] += yoffset;
921 }
922 if(op <= 127) //translucent
923 {
924 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
925 }
926 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
927
928 polygon(refbmp, numpoints, (int32_t*)pos, col);
929 //polygon(refbmp, (sdci[2]/10000), &v, col);
930 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
931 }
932
933 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
934 {
935 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
936
937 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
938 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
939 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
940 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
941 };
942
943 if(sdci[11]/10000 < 128) //translucent
944 {
945 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
946 }
947
948 spline(bmp, points, sdci[10]/10000);
949
950 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
951 }
952
953
954 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
955 {
956 //sdci[1]=layer
957 //sdci[2]=x
958 //sdci[3]=y
959 //sdci[4]=color
960 //sdci[5]=rotation anchor x
961 //sdci[6]=rotation anchor y
962 //sdci[7]=rotation angle
963 //sdci[8]=opacity
964 404879 int32_t x1=sdci[2]/10000;
965 404879 int32_t y1=sdci[3]/10000;
966 404879 int32_t color=sdci[4]/10000;
967
968
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
969 {
970 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
971 16 }
972
973
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
974 {
975 int32_t xy[2];
976 int32_t rx=sdci[5]/10000;
977 int32_t ry=sdci[6]/10000;
978 fixed ra1=itofix(sdci[7]%10000)/10000;
979 fixed ra2=itofix(sdci[7]/10000);
980 fixed ra=ra1+ra2;
981
982 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
983 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
984 x1=xy[0];
985 y1=xy[1];
986 }
987
988 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
989 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
990 404879 }
991
992 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
993 {
994 //Z_scripterrlog("Starting putpixels()%s\n");
995 //sdci[1]=layer
996 //sdci[2]=array {x,y,colour,opacity}
997 //sdci[3]=rotation anchor x
998 //sdci[4]=rotation anchor y
999 //sdci[5]=rotation angle
1000
1001
1002 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1003
1004 if(!v_ptr)
1005 {
1006 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1007 return;
1008 }
1009
1010 std::vector<int32_t> &v = *v_ptr;
1011
1012 if(v.empty())
1013 return;
1014 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1015
1016 int32_t* pos = &v[0];
1017 int32_t sz = v.size();
1018 //Z_scripterrlog("Vector size is: %d\n", sz);
1019 //for ( int32_t m = 0; m < 256; ++m ) Z_scripterrlog("Vector contents at pos[%d]: %d\n", m, pos[m]);
1020
1021 //FFCore.getValues(sdci[2]/10000, points, sz);
1022
1023
1024 int32_t x1 = 0;
1025 int32_t y1 = 0;
1026
1027 for ( int32_t q = 0; q < sz; q+=4 )
1028 {
1029 //Z_scripterrlog("Vector q: %d\n", q);
1030 //if ( q > sz-1 ) break;
1031 x1 = v.at(q); //pos[q];
1032 y1 = v.at(q+1); //pos[q+1];
1033 //Z_scripterrlog("x1 is: %d\n", x1);
1034 //Z_scripterrlog("y1 is: %d\n", 1);
1035 if(sdci[5]!=0) //rotation
1036 {
1037 int32_t xy[2];
1038 int32_t rx=sdci[3]/10000;
1039 int32_t ry=sdci[4]/10000;
1040 fixed ra1=itofix(sdci[5]%10000)/10000;
1041 fixed ra2=itofix(sdci[5]/10000);
1042 fixed ra=ra1+ra2;
1043
1044 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1045 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1046 x1=xy[0];
1047 y1=xy[1];
1048 }
1049 //Z_scripterrlog("PutPixels()%s value is %d\n","x",x1);
1050 //Z_scripterrlog("PutPixels()%s value is %d\n","y",y1);
1051 //Z_scripterrlog("PutPixels()%s value is %d\n","colour",points[q+2]);
1052 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1053 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1054 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1055 //if ( points[q+3] < 128 )
1056
1057 //else drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1058 }
1059 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1060 }
1061
1062 1535849 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1063 {
1064 //sdci[1]=layer
1065 //sdci[2]=x
1066 //sdci[3]=y
1067 //sdci[4]=tile
1068 //sdci[5]=tile width
1069 //sdci[6]=tile height
1070 //sdci[7]=color (cset)
1071 //sdci[8]=scale x
1072 //sdci[9]=scale y
1073 //sdci[10]=rotation anchor x
1074 //sdci[11]=rotation anchor y
1075 //sdci[12]=rotation angle
1076 //sdci[13]=flip
1077 //sdci[14]=transparency
1078 //sdci[15]=opacity
1079
1080 1535849 int32_t w = sdci[5]/10000;
1081 1535849 int32_t h = sdci[6]/10000;
1082
1083
4/8
✓ Branch 0 taken 1535849 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1535849 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1535849 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1535849 times.
1535849 if(w < 1 || h < 1 || h > 20 || w > 20)
1084 {
1085 return;
1086 }
1087
1088 1535849 int32_t xscale=sdci[8]/10000;
1089 1535849 int32_t yscale=sdci[9]/10000;
1090 1535849 int32_t rx = sdci[10]/10000;
1091 1535849 int32_t ry = sdci[11]/10000;
1092 1535849 float rotation=sdci[12]/10000;
1093 1535849 int32_t flip=(sdci[13]/10000)&3;
1094 1535849 bool transparency=sdci[14]!=0;
1095 1535849 int32_t opacity=sdci[15]/10000;
1096 1535849 int32_t color=sdci[7]/10000;
1097
1098 1535849 int32_t x1=sdci[2]/10000;
1099 1535849 int32_t y1=sdci[3]/10000;
1100
1101 //don't scale if it's not safe to do so
1102 1535849 bool canscale = true;
1103
1104
3/4
✓ Branch 0 taken 1515204 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1515204 times.
1535849 if(xscale==0||yscale==0)
1105 {
1106 20645 return;
1107 }
1108
1109
3/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1376239 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138965 times.
1515204 if(xscale<=0||yscale<=0)
1110 1376239 canscale = false; //default size
1111
1112
4/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1376239 times.
✓ Branch 2 taken 130807 times.
✓ Branch 3 taken 1245432 times.
1515204 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1113 {
1114 269772 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1115
1116
1/2
✓ Branch 0 taken 269772 times.
✗ Branch 1 not taken.
269772 if(transparency) //transparency
1117 {
1118 269772 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1119 269772 }
1120 else //no transparency
1121 {
1122 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1123 }
1124
1125
2/2
✓ Branch 0 taken 134495 times.
✓ Branch 1 taken 135277 times.
269772 if(rotation != 0)
1126 {
1127 //low negative values indicate no anchor-point rotation
1128
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 134495 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
134495 if(rx>-777||ry>-777)
1129 {
1130 int32_t xy[2];
1131 134495 fixed ra1=itofix(sdci[12]%10000)/10000;
1132 134495 fixed ra2=itofix(sdci[12]/10000);
1133 134495 fixed ra=ra1+ra2;
1134 134495 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1135 134495 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1136 134495 x1=xy[0];
1137 134495 y1=xy[1];
1138 134495 }
1139
1140
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 130807 times.
134495 if(canscale) //scale first
1141 {
1142 //damnit all, .. fixme.
1143
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1144 3688 clear_bitmap(tempbit);
1145
1146 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1147
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1149 {
1150 clear_bitmap(prim_bmp);
1151 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1152 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1153 }
1154 else
1155 {
1156 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1157 }
1158
1159 3688 destroy_bitmap(tempbit);
1160 3688 }
1161 else //no scale
1162 {
1163
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 127221 times.
130807 if(opacity < 128)
1164 {
1165 3586 clear_bitmap(prim_bmp);
1166 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1167 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1168 3586 }
1169 else
1170 {
1171 127221 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1172 }
1173 }
1174 134495 }
1175 else //scale only
1176 {
1177
1/2
✓ Branch 0 taken 135277 times.
✗ Branch 1 not taken.
135277 if(canscale)
1178 {
1179
2/2
✓ Branch 0 taken 2832 times.
✓ Branch 1 taken 132445 times.
135277 if(opacity<128)
1180 {
1181 2832 clear_bitmap(prim_bmp);
1182 2832 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1183 2832 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1184 2832 }
1185 else
1186 {
1187 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1188 }
1189 135277 }
1190 else //error -do not scale
1191 {
1192 if(opacity<128)
1193 {
1194 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1195 }
1196 else
1197 {
1198 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1199 }
1200 }
1201 }
1202
1203 269772 script_drawing_commands.ReleaseSubBitmap(pbitty);
1204
1205 269772 }
1206 else // no scale or rotation
1207 {
1208
2/2
✓ Branch 0 taken 1217978 times.
✓ Branch 1 taken 27454 times.
1245432 if(transparency)
1209 {
1210
2/2
✓ Branch 0 taken 222546 times.
✓ Branch 1 taken 995432 times.
1217978 if(opacity<=127)
1211 222546 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1212 else
1213 995432 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1214 1217978 }
1215 else
1216 {
1217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1218 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1219 else
1220 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1221 }
1222 }
1223 1535849 }
1224
1225 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1226 {
1227 //sdci[1]=layer
1228 //sdci[2]=x
1229 //sdci[3]=y
1230 //sdci[4]=tile
1231 //sdci[5]=tile width
1232 //sdci[6]=tile height
1233 //sdci[7]=flip
1234
1235 int32_t w = sdci[5]/10000;
1236 int32_t h = sdci[6]/10000;
1237
1238 if(w < 1 || h < 1 || h > 20 || w > 20)
1239 {
1240 return;
1241 }
1242
1243 int32_t flip=(sdci[7]/10000)&3;
1244
1245 int32_t x1=sdci[2]/10000;
1246 int32_t y1=sdci[3]/10000;
1247
1248 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1249 }
1250
1251
1252 2544998 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1253 {
1254 //sdci[1]=layer
1255 //sdci[2]=x
1256 //sdci[3]=y
1257 //sdci[4]=combo
1258 //sdci[5]=tile width
1259 //sdci[6]=tile height
1260 //sdci[7]=color (cset)
1261 //sdci[8]=scale x
1262 //sdci[9]=scale y
1263 //sdci[10]=rotation anchor x
1264 //sdci[11]=rotation anchor y
1265 //sdci[12]=rotation angle
1266 //sdci[13]=frame
1267 //sdci[14]=flip
1268 //sdci[15]=transparency
1269 //sdci[16]=opacity
1270
1271 2544998 int32_t w = sdci[5]/10000;
1272 2544998 int32_t h = sdci[6]/10000;
1273
1274
4/8
✓ Branch 0 taken 2544998 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2544998 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2544998 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2544998 times.
2544998 if(w<1||h<1||h>20||w>20)
1275 {
1276 return;
1277 }
1278 2544998 int32_t cmb = (sdci[4]/10000);
1279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544998 times.
2544998 if((unsigned)cmb >= MAXCOMBOS)
1280 {
1281 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1282 return;
1283 }
1284
1285 2544998 int32_t xscale=sdci[8]/10000;
1286 2544998 int32_t yscale=sdci[9]/10000;
1287 2544998 int32_t rx = sdci[10]/10000; //these work now
1288 2544998 int32_t ry = sdci[11]/10000; //these work now
1289 2544998 float rotation=sdci[12]/10000;
1290
1291 2544998 bool transparency=sdci[15]!=0;
1292 2544998 int32_t opacity=sdci[16]/10000;
1293 2544998 int32_t color=sdci[7]/10000;
1294 2544998 int32_t x1=sdci[2]/10000;
1295 2544998 int32_t y1=sdci[3]/10000;
1296
1297 2544998 const newcombo & c = combobuf[cmb];
1298 2544998 int32_t tiletodraw = combo_tile(c, x1, y1);
1299 2544998 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1300 2544998 int32_t skiprows=c.skipanimy;
1301
1302
1303 //don't scale if it's not safe to do so
1304 2544998 bool canscale = true;
1305
1306
3/4
✓ Branch 0 taken 2544947 times.
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2544947 times.
2544998 if(xscale==0||yscale==0)
1307 {
1308 51 return;
1309 }
1310
1311
3/4
✓ Branch 0 taken 22484 times.
✓ Branch 1 taken 2522463 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22484 times.
2544947 if(xscale<=0||yscale<=0)
1312 2522463 canscale = false; //default size
1313
1314
4/4
✓ Branch 0 taken 22484 times.
✓ Branch 1 taken 2522463 times.
✓ Branch 2 taken 98637 times.
✓ Branch 3 taken 2423826 times.
2544947 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1315 {
1316 121121 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1317
1318
2/2
✓ Branch 0 taken 120085 times.
✓ Branch 1 taken 1036 times.
121121 if(transparency)
1319 {
1320 120085 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1321 120085 }
1322 else //no transparency
1323 {
1324 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1325 }
1326
1327
2/2
✓ Branch 0 taken 98746 times.
✓ Branch 1 taken 22375 times.
121121 if(rotation != 0) // rotate
1328 {
1329 //fixed point sucks ;0
1330
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98746 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
98746 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1331 {
1332 int32_t xy[2];
1333 98746 fixed ra1=itofix(sdci[12]%10000)/10000;
1334 98746 fixed ra2=itofix(sdci[12]/10000);
1335 98746 fixed ra=ra1+ra2;
1336 98746 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1337 98746 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1338 98746 x1=xy[0];
1339 98746 y1=xy[1];
1340 98746 }
1341
1342
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 98637 times.
98746 if(canscale) //scale first
1343 {
1344
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 109 times.
109 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1345 109 clear_bitmap(tempbit);
1346
1347 109 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1348
1349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
109 if(opacity < 128)
1350 {
1351 clear_bitmap(prim_bmp);
1352 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1353 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1354 }
1355 else
1356 {
1357 109 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1358 }
1359
1360 109 destroy_bitmap(tempbit);
1361 109 }
1362 else //no scale
1363 {
1364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98637 times.
98637 if(opacity < 128)
1365 {
1366 clear_bitmap(prim_bmp);
1367 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1368 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1369 }
1370 else
1371 {
1372 98637 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1373 }
1374 }
1375 98746 }
1376 else //scale only
1377 {
1378
1/2
✓ Branch 0 taken 22375 times.
✗ Branch 1 not taken.
22375 if(canscale)
1379 {
1380
2/2
✓ Branch 0 taken 9333 times.
✓ Branch 1 taken 13042 times.
22375 if(opacity<128)
1381 {
1382 9333 clear_bitmap(prim_bmp);
1383 9333 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1384 9333 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1385 9333 }
1386 else
1387 {
1388 13042 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1389 }
1390 22375 }
1391 else //error -do not scale
1392 {
1393 if(opacity<128)
1394 {
1395 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1396 }
1397 else
1398 {
1399 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1400 }
1401 }
1402 }
1403
1404 121121 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1405 121121 }
1406 else // no scale or rotation
1407 {
1408
1/2
✓ Branch 0 taken 2423826 times.
✗ Branch 1 not taken.
2423826 if(transparency)
1409 {
1410
2/2
✓ Branch 0 taken 60880 times.
✓ Branch 1 taken 2362946 times.
2423826 if(opacity<=127)
1411 60880 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1412 else
1413 2362946 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1414 2423826 }
1415 else
1416 {
1417 if(opacity<=127)
1418 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1419 else
1420 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1421 }
1422 }
1423 2544998 }
1424
1425 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1426 {
1427 //sdci[1]=layer
1428 //sdci[2]=x
1429 //sdci[3]=y
1430 //sdci[4]=combo
1431 //sdci[5]=tile width
1432 //sdci[6]=tile height
1433 //sdci[7]=flip
1434
1435 int32_t w = sdci[5]/10000;
1436 int32_t h = sdci[6]/10000;
1437
1438 if(w<1||h<1||h>20||w>20)
1439 {
1440 return;
1441 }
1442 int32_t cmb = (sdci[4]/10000);
1443 if((unsigned)cmb >= MAXCOMBOS)
1444 {
1445 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1446 return;
1447 }
1448
1449 int32_t x1=sdci[2]/10000;
1450 int32_t y1=sdci[3]/10000;
1451
1452 const newcombo & c = combobuf[cmb];
1453 int32_t tiletodraw = combo_tile(c, x1, y1);
1454 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1455 int32_t skiprows=c.skipanimy;
1456
1457 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1458 }
1459
1460
1461 5287220 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1462 {
1463 /* layer, x, y, tile, color opacity */
1464
1465 5287220 int32_t opacity = sdci[6]/10000;
1466
1467
2/2
✓ Branch 0 taken 153668 times.
✓ Branch 1 taken 5133552 times.
5287220 if(opacity < 128)
1468 153668 overtiletranslucent16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
1469 else
1470 5133552 overtile16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
1471 5287220 }
1472
1473 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1474 {
1475 /* layer, x, y, tile, color opacity */
1476
1477 //sdci[1]=layer
1478 //sdci[2]=array {x,y,tile,colour,opacity}
1479
1480 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1481
1482 if(!v_ptr)
1483 {
1484 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1485 return;
1486 }
1487
1488 std::vector<int32_t> &v = *v_ptr;
1489
1490 if(v.empty())
1491 return;
1492 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1493
1494 int32_t* pos = &v[0];
1495 int32_t sz = v.size();
1496
1497 for ( int32_t q = 0; q < sz; q+=5 )
1498 {
1499
1500 if(v.at(q+4) < 128)
1501 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1502 else
1503 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1504 }
1505 }
1506
1507
1508
1509 21409189 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1510 {
1511 /* layer, x, y, tile, color opacity */
1512
1513 21409189 int32_t opacity = sdci[6] / 10000;
1514 21409189 int32_t x1 = sdci[2] / 10000;
1515 21409189 int32_t y1 = sdci[3] / 10000;
1516
1517 21409189 int32_t cmb = (sdci[4]/10000);
1518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21409189 times.
21409189 if((unsigned)cmb >= MAXCOMBOS)
1519 {
1520 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1521 return;
1522 }
1523
1524
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 21231793 times.
21409189 if(opacity < 128)
1525 {
1526 177396 overcomboblocktranslucent(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
1527
1528 177396 }
1529 else
1530 {
1531 21231793 overcomboblock(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
1532 }
1533 21409189 }
1534
1535 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1536 {
1537 /* layer, x, y, combo, cset, opacity */
1538 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1539
1540 if(!v_ptr)
1541 {
1542 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1543 return;
1544 }
1545
1546 std::vector<int32_t> &v = *v_ptr;
1547
1548 if(v.empty())
1549 return;
1550
1551 int32_t* pos = &v[0];
1552 int32_t sz = v.size();
1553
1554 for ( int32_t q = 0; q < sz; q+=5 )
1555 {
1556 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1557 {
1558 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1559 continue;
1560 }
1561 if(v.at(q+4) < 128)
1562 {
1563 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1564
1565 }
1566 else
1567 {
1568 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1569 }
1570 }
1571 }
1572
1573
1574
1575
1576 962949 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1577 {
1578 //broken 2.50.2 and earlier drawcharacter()
1579
2/2
✓ Branch 0 taken 17778 times.
✓ Branch 1 taken 945171 times.
962949 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1580 {
1581 //sdci[1]=layer
1582 //sdci[2]=x
1583 //sdci[3]=y
1584 //sdci[4]=font
1585 //sdci[5]=color
1586 //sdci[6]=bg color
1587 //sdci[7]=strech x (width)
1588 //sdci[8]=stretch y (height)
1589 //sdci[9]=char
1590 //sdci[10]=opacity
1591
1592 17778 int32_t x=sdci[2]/10000;
1593 17778 int32_t y=sdci[3]/10000;
1594 17778 int32_t font_index=sdci[4]/10000;
1595 17778 int32_t color=sdci[5]/10000;
1596 17778 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1597 17778 int32_t w=sdci[7]/10000;
1598 17778 int32_t h=sdci[8]/10000;
1599 17778 char glyph=char(sdci[9]/10000);
1600 17778 int32_t opacity=sdci[10]/10000;
1601
1602 //safe check
1603
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(bg_color < -1) bg_color = -1;
1604
1605
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(w>512) w=512; //w=vbound(w,0,512);
1606
1607
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(h>512) h=512; //h=vbound(h,0,512);
1608
1609 //undone
1610
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17778 if(w>0&&h>0)//stretch the character
1611 {
1612 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1613
1614 if(opacity < 128)
1615 {
1616 if(w>128||h>128)
1617 {
1618 clear_bitmap(prim_bmp);
1619
1620 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1621 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1622 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1623 }
1624 else //this is faster
1625 {
1626 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1627
1628 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1629 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1630 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1631
1632 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1633 }
1634 }
1635 else // no opacity
1636 {
1637 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1638 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1639 }
1640
1641 }
1642 else //no stretch
1643 {
1644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
17778 if(opacity < 128)
1645 {
1646 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1647 clear_bitmap(pbmp);
1648
1649 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1650 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1651
1652 destroy_bitmap(pbmp);
1653 }
1654 else // no opacity
1655 {
1656 17778 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1657 }
1658 }
1659 17778 }
1660
1661 else //2.53.0 fixed version and later.
1662 {
1663
1664 //sdci[1]=layer
1665 //sdci[2]=x
1666 //sdci[3]=y
1667 //sdci[4]=font
1668 //sdci[5]=color
1669 //sdci[6]=bg color
1670 //sdci[7]=strech x (width)
1671 //sdci[8]=stretch y (height)
1672 //sdci[9]=char
1673 //sdci[10]=opacity
1674
1675 945171 int32_t x=sdci[2]/10000;
1676 945171 int32_t y=sdci[3]/10000;
1677 945171 int32_t font_index=sdci[4]/10000;
1678 945171 int32_t color=sdci[5]/10000;
1679 945171 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1680 945171 int32_t w=sdci[7]/10000;
1681 945171 int32_t h=sdci[8]/10000;
1682 945171 char glyph=char(sdci[9]/10000);
1683 945171 int32_t opacity=sdci[10]/10000;
1684
1685 //safe check
1686
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(bg_color < -1) bg_color = -1;
1687
1688
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(w>512) w=512; //w=vbound(w,0,512);
1689
1690
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(h>512) h=512; //h=vbound(h,0,512);
1691
1692 //undone
1693
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945171 if(w>0&&h>0)//stretch the character
1694 {
1695 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1696
1697 if(opacity < 128)
1698 {
1699 if(w>128||h>128)
1700 {
1701 clear_bitmap(prim_bmp);
1702
1703 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1704 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1705 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1706 }
1707 else //this is faster
1708 {
1709 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1710
1711 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1712 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1713 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1714
1715 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1716 }
1717 }
1718 else // no opacity
1719 {
1720 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1721 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1722 }
1723
1724 }
1725 else //no stretch
1726 {
1727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
945171 if(opacity < 128)
1728 {
1729 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1730 clear_bitmap(pbmp);
1731
1732 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1733 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1734
1735 destroy_bitmap(pbmp);
1736 }
1737 else // no opacity
1738 {
1739 945171 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1740 }
1741 }
1742
1743 }
1744
1745 962949 }
1746
1747
1748 142863 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1749 {
1750 //broken 2.50.2 and earlier drawinteger()
1751
2/2
✓ Branch 0 taken 72533 times.
✓ Branch 1 taken 70330 times.
142863 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1752 {
1753 //sdci[1]=layer
1754 //sdci[2]=x
1755 //sdci[3]=y
1756 //sdci[4]=font
1757 //sdci[5]=color
1758 //sdci[6]=bg color
1759 //sdci[7]=strech x (width)
1760 //sdci[8]=stretch y (height)
1761 //sdci[9]=integer
1762 //sdci[10]=num decimal places
1763 //sdci[11]=opacity
1764
1765 72533 int32_t x=sdci[2]/10000;
1766 72533 int32_t y=sdci[3]/10000;
1767 72533 int32_t font_index=sdci[4]/10000;
1768 72533 int32_t color=sdci[5]/10000;
1769 72533 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1770 72533 int32_t w=sdci[7]/10000;
1771 72533 int32_t h=sdci[8]/10000;
1772 72533 int32_t decplace=sdci[10]/10000;
1773 72533 int32_t opacity=sdci[11]/10000;
1774
1775 //safe check
1776
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(bg_color < -1) bg_color = -1;
1777
1778
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(w>512) w=512; //w=vbound(w,0,512);
1779
1780
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(h>512) h=512; //h=vbound(h,0,512);
1781
1782 char numbuf[15];
1783
1784
1/6
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72533 switch(decplace)
1785 {
1786 default:
1787 case 0:
1788 72533 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1789 72533 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1790
1791 case 1:
1792 //sprintf(numbuf,"%.01f",number);
1793 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1794 break;
1795
1796 case 2:
1797 //sprintf(numbuf,"%.02f",number);
1798 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1799 break;
1800
1801 case 3:
1802 //sprintf(numbuf,"%.03f",number);
1803 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1804 break;
1805
1806 case 4:
1807 //sprintf(numbuf,"%.04f",number);
1808 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1809 break;
1810 }
1811
1812
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72533 if(w>0&&h>0)//stretch
1813 {
1814 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1815
1816 if(opacity < 128)
1817 {
1818 if(w>128||h>128)
1819 {
1820 clear_bitmap(prim_bmp);
1821
1822 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1823 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1824 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1825 }
1826 else
1827 {
1828 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1829 clear_bitmap(pbmp2);
1830
1831 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1832 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1833 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1834
1835 destroy_bitmap(pbmp2);
1836 }
1837 }
1838 else // no opacity
1839 {
1840 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1841 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1842 }
1843
1844 }
1845 else //no stretch
1846 {
1847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
72533 if(opacity < 128)
1848 {
1849 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1850 clear_bitmap(pbmp);
1851
1852 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1853 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1854
1855 destroy_bitmap(pbmp);
1856 }
1857 else // no opacity
1858 {
1859 72533 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1860 }
1861 }
1862
1863 72533 }
1864
1865 else //2.53.0 fixed version and later.
1866 {
1867 //sdci[1]=layer
1868 //sdci[2]=x
1869 //sdci[3]=y
1870 //sdci[4]=font
1871 //sdci[5]=color
1872 //sdci[6]=bg color
1873 //sdci[7]=strech x (width)
1874 //sdci[8]=stretch y (height)
1875 //sdci[9]=integer
1876 //sdci[10]=num decimal places
1877 //sdci[11]=opacity
1878
1879 70330 int32_t x=sdci[2]/10000;
1880 70330 int32_t y=sdci[3]/10000;
1881 70330 int32_t font_index=sdci[4]/10000;
1882 70330 int32_t color=sdci[5]/10000;
1883 70330 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1884 70330 int32_t w=sdci[7]/10000;
1885 70330 int32_t h=sdci[8]/10000;
1886 70330 int32_t decplace=sdci[10]/10000;
1887 70330 int32_t opacity=sdci[11]/10000;
1888
1889 //safe check
1890
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(bg_color < -1) bg_color = -1;
1891
1892
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(w>512) w=512; //w=vbound(w,0,512);
1893
1894
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(h>512) h=512; //h=vbound(h,0,512);
1895
1896 char numbuf[15];
1897
1898
1/6
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
70330 switch(decplace)
1899 {
1900 default:
1901 case 0:
1902 70330 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1903 70330 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1904
1905 case 1:
1906 //sprintf(numbuf,"%.01f",number);
1907 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1908 break;
1909
1910 case 2:
1911 //sprintf(numbuf,"%.02f",number);
1912 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1913 break;
1914
1915 case 3:
1916 //sprintf(numbuf,"%.03f",number);
1917 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1918 break;
1919
1920 case 4:
1921 //sprintf(numbuf,"%.04f",number);
1922 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1923 break;
1924 }
1925
1926 //FONT* font=get_zc_font(sdci[4]/10000);
1927
1928
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 70330 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
70330 if(w>0&&h>0)//stretch
1929 {
1930 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
1931 clear_bitmap(pbmp);
1932 //script_drawing_commands.GetSmallTextureBitmap(1,1);
1933
1934 if(opacity < 128)
1935 {
1936 if(w>128||h>128)
1937 {
1938 clear_bitmap(prim_bmp);
1939
1940 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1941 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1942 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1943 }
1944 else
1945 {
1946 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1947 clear_bitmap(pbmp2);
1948
1949 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1950 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1951 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1952
1953 destroy_bitmap(pbmp2);
1954 }
1955 }
1956 else // no opacity
1957 {
1958 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1959 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1960 }
1961
1962 }
1963 else //no stretch
1964 {
1965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70330 times.
70330 if(opacity < 128)
1966 {
1967 FONT* font = get_zc_font(font_index);
1968 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
1969 clear_bitmap(pbmp);
1970
1971 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
1972 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1973
1974 destroy_bitmap(pbmp);
1975 }
1976 else // no opacity
1977 {
1978 70330 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1979 }
1980 }
1981 }
1982 142863 }
1983
1984
1985 1530571 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1986 {
1987 //sdci[1]=layer
1988 //sdci[2]=x
1989 //sdci[3]=y
1990 //sdci[4]=font
1991 //sdci[5]=color
1992 //sdci[6]=bg color
1993 //sdci[7]=format_option
1994 //sdci[8]=string
1995 //sdci[9]=opacity
1996
1997 1530571 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
1998
1999
1/2
✓ Branch 0 taken 1530571 times.
✗ Branch 1 not taken.
1530571 if(!str)
2000 {
2001 al_trace("String pointer is null! Internal error. \n");
2002 return;
2003 }
2004
2005 1530571 int32_t x=sdci[2]/10000;
2006 1530571 int32_t y=sdci[3]/10000;
2007 1530571 FONT* font=get_zc_font(sdci[4]/10000);
2008 1530571 int32_t color=sdci[5]/10000;
2009 1530571 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2010 1530571 int32_t format_type=sdci[7]/10000;
2011 1530571 int32_t opacity=sdci[9]/10000;
2012 //sdci[8] not needed :)
2013
2014 //safe check
2015
1/2
✓ Branch 0 taken 1530571 times.
✗ Branch 1 not taken.
1530571 if(bg_color < -1) bg_color = -1;
2016
2017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1530571 times.
1530571 if(opacity < 128)
2018 {
2019 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2020 if (width < 1) return; //SANITY -Em
2021 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2022 clear_bitmap(pbmp);
2023 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2024 if(format_type == 2) // right-sided text
2025 x-=width;
2026 else if(format_type == 1) // centered text
2027 x-=width/2;
2028 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2029 destroy_bitmap(pbmp);
2030 }
2031 else // no opacity
2032 {
2033
2/2
✓ Branch 0 taken 11785 times.
✓ Branch 1 taken 1518786 times.
1530571 if(format_type == 2) // right-sided text
2034 {
2035 11785 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2036 11785 }
2037
2/2
✓ Branch 0 taken 723406 times.
✓ Branch 1 taken 795380 times.
1518786 else if(format_type == 1) // centered text
2038 {
2039 723406 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2040 723406 }
2041 else // standard left-sided text
2042 {
2043 795380 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2044 }
2045 }
2046 1530571 }
2047
2048 163717 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2049 {
2050 //sdci[1]=layer
2051 //sdci[2]=x
2052 //sdci[3]=y
2053 //sdci[4]=font
2054 //sdci[5]=color
2055 //sdci[6]=bg color
2056 //sdci[7]=format_option
2057 //sdci[8]=string
2058 //sdci[9]=opacity
2059 //sdci[10]=shadowtype
2060 //sdci[11]=shadow_color
2061
2062 163717 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2063
2064
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(!str)
2065 {
2066 al_trace("String pointer is null! Internal error. \n");
2067 return;
2068 }
2069
2070 163717 int32_t x=sdci[2]/10000;
2071 163717 int32_t y=sdci[3]/10000;
2072 163717 FONT* font=get_zc_font(sdci[4]/10000);
2073 163717 int32_t color=sdci[5]/10000;
2074 163717 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2075 163717 int32_t format_type=sdci[7]/10000;
2076 163717 int32_t opacity=sdci[9]/10000;
2077 163717 int32_t textstyle = sdci[10]/10000;
2078 163717 int32_t shadow_color = sdci[11]/10000;
2079 //sdci[8] not needed :)
2080
2081 //safe check
2082
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(bg_color < -1) bg_color = -1;
2083
2084
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162977 times.
163717 if(opacity < 128)
2085 {
2086
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2087
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2088 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2089 740 clear_bitmap(pbmp);
2090 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2091 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2093 x-=width;
2094
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2095 740 x-=width/2;
2096 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2097 740 destroy_bitmap(pbmp);
2098 740 }
2099 else // no opacity
2100 {
2101 162977 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2102 }
2103 163717 }
2104
2105
2106 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2107 {
2108 //sdci[1]=layer
2109 //sdci[2]=x1
2110 //sdci[3]=y1
2111 //sdci[4]=x2
2112 //sdci[5]=y2
2113 //sdci[6]=x3
2114 //sdci[7]=y3
2115 //sdci[8]=x4
2116 //sdci[9]=y4
2117 //sdci[10]=width
2118 //sdci[11]=height
2119 //sdci[12]=cset
2120 //sdci[13]=flip
2121 //sdci[14]=tile/combo
2122 //sdci[15]=polytype
2123
2124 9266 int32_t x1 = sdci[2]/10000;
2125 9266 int32_t y1 = sdci[3]/10000;
2126 9266 int32_t x2 = sdci[4]/10000;
2127 9266 int32_t y2 = sdci[5]/10000;
2128 9266 int32_t x3 = sdci[6]/10000;
2129 9266 int32_t y3 = sdci[7]/10000;
2130 9266 int32_t x4 = sdci[8]/10000;
2131 9266 int32_t y4 = sdci[9]/10000;
2132 9266 int32_t w = sdci[10]/10000;
2133 9266 int32_t h = sdci[11]/10000;
2134 9266 int32_t color = sdci[12]/10000;
2135 9266 int32_t flip=(sdci[13]/10000)&3;
2136 9266 int32_t tile = sdci[14]/10000;
2137 9266 int32_t polytype = sdci[15]/10000;
2138
2139 //todo: finish palette shading
2140 /*
2141 POLYTYPE_FLAT
2142 POLYTYPE_GCOL
2143 POLYTYPE_GRGB
2144 POLYTYPE_ATEX
2145 POLYTYPE_PTEX
2146 POLYTYPE_ATEX_MASK
2147 POLYTYPE_PTEX_MASK
2148 POLYTYPE_ATEX_LIT
2149 POLYTYPE_PTEX_LIT
2150 POLYTYPE_ATEX_MASK_LIT
2151 POLYTYPE_PTEX_MASK_LIT
2152 POLYTYPE_ATEX_TRANS
2153 POLYTYPE_PTEX_TRANS
2154 POLYTYPE_ATEX_MASK_TRANS
2155 POLYTYPE_PTEX_MASK_TRANS
2156 */
2157 9266 polytype = vbound(polytype, 0, 14);
2158
2159
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2160 {
2161 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2162 return; //non power of two error
2163 }
2164
2165 9266 int32_t tex_width = w*16;
2166 9266 int32_t tex_height = h*16;
2167
2168 BITMAP *tex;
2169
2170 9266 bool mustDestroyBmp = false;
2171
2172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2173 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2174
2175
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2176 {
2177 mustDestroyBmp = true;
2178 tex = create_bitmap_ex(8, tex_width, tex_height);
2179 clear_bitmap(tex);
2180 }
2181
2182 int32_t col[4];
2183 /*
2184 if( color < 0 )
2185 {
2186 col[0]=draw_container.color_buffer[0];
2187 col[1]=draw_container.color_buffer[1];
2188 col[2]=draw_container.color_buffer[2];
2189 col[3]=draw_container.color_buffer[3];
2190 }
2191 else */
2192 {
2193 9266 col[0]=col[1]=col[2]=col[3]=color;
2194 }
2195
2196
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2197 {
2198 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2199 }
2200
2201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2202 {
2203 9266 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2204 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2205 9266 flip = flip ^ c.flip;
2206
2207 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2208 9266 }
2209
2210 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2211 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2212 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2213 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2214
2215 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2216
2217
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2218 destroy_bitmap(tex);
2219
2220 9266 }
2221
2222
2223 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2224 {
2225 //sdci[1]=layer
2226 //sdci[2]=x1
2227 //sdci[3]=y1
2228 //sdci[4]=x2
2229 //sdci[5]=y2
2230 //sdci[6]=x3
2231 //sdci[7]=y3
2232 //sdci[8]=width
2233 //sdci[9]=height
2234 //sdci[10]=cset
2235 //sdci[11]=flip
2236 //sdci[12]=tile/combo
2237 //sdci[13]=polytype
2238
2239 int32_t x1 = sdci[2]/10000;
2240 int32_t y1 = sdci[3]/10000;
2241 int32_t x2 = sdci[4]/10000;
2242 int32_t y2 = sdci[5]/10000;
2243 int32_t x3 = sdci[6]/10000;
2244 int32_t y3 = sdci[7]/10000;
2245 int32_t w = sdci[8]/10000;
2246 int32_t h = sdci[9]/10000;
2247 int32_t color = sdci[10]/10000;
2248 int32_t flip=(sdci[11]/10000)&3;
2249 int32_t tile = sdci[12]/10000;
2250 int32_t polytype = sdci[13]/10000;
2251
2252 polytype = vbound(polytype, 0, 14);
2253
2254 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2255 {
2256 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2257 return; //non power of two error
2258 }
2259
2260 int32_t tex_width = w*16;
2261 int32_t tex_height = h*16;
2262
2263 bool mustDestroyBmp = false;
2264 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2265
2266 if(!tex)
2267 {
2268 mustDestroyBmp = true;
2269 tex = create_bitmap_ex(8, tex_width, tex_height);
2270 clear_bitmap(tex);
2271 }
2272
2273 int32_t col[3];
2274 /*
2275 if( color < 0 )
2276 {
2277 col[0]=draw_container.color_buffer[0];
2278 col[1]=draw_container.color_buffer[1];
2279 col[2]=draw_container.color_buffer[2];
2280 }
2281 else */
2282 {
2283 col[0]=col[1]=col[2]=color;
2284 }
2285
2286 if(tile > 0) // TILE
2287 {
2288 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2289 }
2290 else // COMBO
2291 {
2292 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2293 const int32_t tiletodraw = combo_tile(c, x1, y1);
2294 flip = flip ^ c.flip;
2295
2296 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2297 }
2298
2299 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2300 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2301 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2302
2303
2304 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2305
2306 if(mustDestroyBmp)
2307 destroy_bitmap(tex);
2308 }
2309
2310
2311 928052 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2312 {
2313 //sdci[1]=layer
2314 //sdci[2]=bitmap
2315 //sdci[3]=sourcex
2316 //sdci[4]=sourcey
2317 //sdci[5]=sourcew
2318 //sdci[6]=sourceh
2319 //sdci[7]=destx
2320 //sdci[8]=desty
2321 //sdci[9]=destw
2322 //sdci[10]=desth
2323 //sdci[11]=rotation
2324 //sdci[12]=mask
2325
2326 928052 int32_t bitmapIndex = sdci[2]/10000;
2327 928052 int32_t sx = sdci[3]/10000;
2328 928052 int32_t sy = sdci[4]/10000;
2329 928052 int32_t sw = sdci[5]/10000;
2330 928052 int32_t sh = sdci[6]/10000;
2331 928052 int32_t dx = sdci[7]/10000;
2332 928052 int32_t dy = sdci[8]/10000;
2333 928052 int32_t dw = sdci[9]/10000;
2334 928052 int32_t dh = sdci[10]/10000;
2335 928052 float rot = sdci[11]/10000;
2336 928052 bool masked = (sdci[12] != 0);
2337
2338 //bugfix
2339 928052 sx = vbound(sx, 0, 512);
2340 928052 sy = vbound(sy, 0, 512);
2341 928052 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2342 928052 sh = vbound(sh, 0, 512 - sy);
2343
2344
2345
2/4
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 928052 times.
928052 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2346 return;
2347
2348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 928052 times.
928052 bool stretched = (sw != dw || sh != dh);
2349
2350 928052 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2351
2352
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(!sourceBitmap)
2353 {
2354 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2355 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2356 return;
2357 }
2358
2359 928052 BITMAP* subBmp = 0;
2360
2361
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(rot != 0)
2362 {
2363 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2364
2365 if(!subBmp)
2366 {
2367 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2368 return;
2369 }
2370 }
2371
2372
2373 928052 dx = dx + xoffset;
2374 928052 dy = dy + yoffset;
2375
2376
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 927812 times.
928052 if(stretched)
2377 {
2378
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2379 {
2380
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2381 {
2382 //if ( rot == 4096 ) { //translucent
2383 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2384 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2385 // draw_trans_sprite(bmp, subBmp, dx, dy);
2386 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2387
2388
2389 // }
2390 //else {
2391 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2392 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2393 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2394 //
2395
2396 // }
2397 }
2398 else
2399 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2400 240 }
2401 else
2402 {
2403 if(rot != 0)
2404 {
2405 //if ( rot == 4096 ) { //translucent
2406 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2407 // draw_trans_sprite(bmp, subBmp, dx, dy);
2408 // }
2409 //else {
2410 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2411 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2412 // }
2413 }
2414 else
2415 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2416 }
2417 240 }
2418 else
2419 {
2420
2/2
✓ Branch 0 taken 923090 times.
✓ Branch 1 taken 4722 times.
927812 if(masked)
2421 {
2422
1/2
✓ Branch 0 taken 923090 times.
✗ Branch 1 not taken.
923090 if(rot != 0)
2423 {
2424 //if ( rot == 4096 ) {//translucent
2425 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2426 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2427
2428 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2429 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2430 // draw_trans_sprite(bmp, subBmp, dx, dy);
2431 // }
2432 //else {
2433 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2434 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2435 // }
2436 }
2437 else
2438 923090 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2439 923090 }
2440 else
2441 {
2442
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2443 {
2444 //if ( rot == 4096 ) { //translucent
2445 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2446 // draw_trans_sprite(bmp, subBmp, dx, dy);
2447 // }
2448 //else {
2449 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2450 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2451 // }
2452 }
2453 else
2454 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2455 }
2456 }
2457
2458 //cleanup
2459
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(subBmp)
2460 {
2461 script_drawing_commands.ReleaseSubBitmap(subBmp);
2462 }
2463 928052 }
2464
2465
2466 //Draw]()
2467 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2468 {
2469 /*
2470 //sdci[1]=layer
2471 //sdci[2]=bitmap
2472 //sdci[3]=sourcex
2473 //sdci[4]=sourcey
2474 //sdci[5]=sourcew
2475 //sdci[6]=sourceh
2476 //sdci[7]=destx
2477 //sdci[8]=desty
2478 //sdci[9]=destw
2479 //sdci[10]=desth
2480 //sdci[11]=rotation/angle
2481 //scdi[12] = pivot cx
2482 //sdci[13] = pivot cy
2483 //scdi[14] = effect flags
2484
2485
2486 const int32_t BITDX_NORMAL = 0;
2487 const int32_t BITDX_TRANS = 1; //Translucent
2488 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2489 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2490 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2491 //Note: Some modes cannot be combined. if a combination is not supported, an error
2492 // detailing this will be shown in allegro.log.
2493
2494 //scdi[15] = litcolour
2495 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2496 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2497
2498 //sdci[16]=mask
2499
2500 */
2501
2502 int32_t bitmapIndex = sdci[2]/10000;
2503 int32_t sx = sdci[3]/10000;
2504 int32_t sy = sdci[4]/10000;
2505 int32_t sw = sdci[5]/10000;
2506 int32_t sh = sdci[6]/10000;
2507 int32_t dx = sdci[7]/10000;
2508 int32_t dy = sdci[8]/10000;
2509 int32_t dw = sdci[9]/10000;
2510 int32_t dh = sdci[10]/10000;
2511 float rot = sdci[11]/10000;
2512 int32_t cx = sdci[12]/10000;
2513 int32_t cy = sdci[13]/10000;
2514 int32_t mode = sdci[14]/10000;
2515 int32_t litcolour = sdci[15]/10000;
2516 bool masked = (sdci[16] != 0);
2517
2518
2519
2520 //bugfix
2521 sx = vbound(sx, 0, 512);
2522 sy = vbound(sy, 0, 512);
2523 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2524 sh = vbound(sh, 0, 512 - sy);
2525
2526
2527 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2528 return;
2529
2530 bool stretched = (sw != dw || sh != dh);
2531
2532 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2533
2534 if(!sourceBitmap)
2535 {
2536 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2537 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2538 return;
2539 }
2540
2541 BITMAP* subBmp = 0;
2542
2543 /*
2544 if ( bitmapIndex == -1 ) {
2545 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2546 }
2547 */
2548
2549 if(rot != 0 || mode != 0)
2550 {
2551 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2552
2553 if(!subBmp)
2554 {
2555 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2556 return;
2557 }
2558 }
2559
2560
2561 dx = dx + xoffset;
2562 dy = dy + yoffset;
2563
2564 if(stretched)
2565 {
2566 if(masked) //stretched and masked
2567 {
2568 if ( rot == 0 ) //if not rotated
2569 {
2570 switch(mode)
2571 {
2572 case 1:
2573 //transparent
2574 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2575 draw_trans_sprite(bmp, subBmp, dx, dy);
2576 break;
2577
2578
2579 case 2:
2580 //pivot?
2581 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2582 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2583 //Pivoting requires two more args
2584 break;
2585
2586 case 3:
2587 //pivot + trans
2588 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2589 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2590 break;
2591
2592 case 4:
2593 //flip v
2594 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2595 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2596 break;
2597
2598 case 5:
2599 //trans + v flip
2600 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2601 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2602 break;
2603
2604 case 6:
2605 //pivot + v flip
2606 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2607 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2608 break;
2609
2610 case 8:
2611 //vlip h
2612 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2613 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2614 break;
2615
2616 case 9:
2617 //trans + h flip
2618 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2619 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2620 break;
2621
2622 case 10:
2623 //flip H and pivot
2624 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2625 //return error cannot pivot and h flip
2626 break;
2627
2628 case 12:
2629 //vh flip
2630 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2631 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2632 break;
2633
2634 case 13:
2635 //trans + vh flip
2636 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2637 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2638 break;
2639
2640 case 14:
2641 //pivot and vh flip
2642 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2643 //return error cannot both pivot and vh flip
2644 break;
2645
2646 case 16:
2647 //lit
2648 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2649 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2650 break;
2651
2652 case 18:
2653 //pivot, lit
2654 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2655 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2656 break;
2657
2658 case 20:
2659 //lit + v flip
2660 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2661 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2662 break;
2663
2664 case 22:
2665 //Pivot, vflip, lit
2666 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2667 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2668 break;
2669
2670 case 24:
2671 //lit + h flip
2672 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2673 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2674 break;
2675
2676 case 26:
2677 //pivot + lit + hflip
2678 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2679 //return error cannot pivot, lit, and flip
2680 break;
2681
2682 case 28:
2683 //lit + vh flip
2684 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2685 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2686 break;
2687
2688 case 32: //gouraud
2689 //Probably not wort supporting.
2690 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2691 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2692 break;
2693
2694 case 0:
2695 //no effect
2696 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2697 break;
2698
2699
2700 default:
2701 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2702
2703
2704 }
2705 } //end if not rotated
2706
2707 if ( rot != 0 ) //if rotated
2708 {
2709 switch(mode)
2710 {
2711 case 1:
2712 //transparent
2713 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2714 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2715
2716 break;
2717
2718 case 2:
2719 //pivot?
2720 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2721 //return an error, cannot both rotate and pivot
2722 break;
2723
2724 case 3:
2725 //pivot + trans
2726 //return an error, cannot both rotate and pivot
2727 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2728 break;
2729
2730 case 4:
2731 //flip v
2732 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2733 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2734 break;
2735
2736 case 5:
2737 //trans + v flip
2738 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2739 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2740 break;
2741
2742 case 6:
2743 //pivot + v flip
2744 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2745 //return an error, cannot both rotate and pivot
2746 break;
2747
2748 case 8:
2749 //flip h
2750 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2751 //return an error, cannot both rotate and flip H
2752 break;
2753
2754 case 9:
2755 //trans + h flip
2756 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2757 //return an error, cannot rotate and flip a trans sprite
2758 break;
2759
2760 case 10:
2761 //flip H and pivot
2762 //return error cannot pivot and h flip
2763 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2764 break;
2765
2766 case 12:
2767 //vh flip
2768 //return an error, cannot rotate and VH flip a trans sprite
2769 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2770 break;
2771
2772 case 13:
2773 //trans + vh flip
2774 //return an error, cannot rotate and VH flip a trans sprite
2775 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2776 break;
2777
2778 case 14:
2779 //pivot and vh flip
2780 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2781 //return error cannot both pivot and vh flip
2782 break;
2783
2784 case 16:
2785 //lit
2786 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2787 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2788 break;
2789
2790 case 18:
2791 //pivot, lit
2792 //return an error, cannot both rotate and pivot
2793 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2794 break;
2795
2796 case 20:
2797 //lit + vflip
2798 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2799 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2800 break;
2801
2802 case 22:
2803 //Pivot, vflip, lit
2804 //return an error, cannot both rotate and pivot
2805 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2806 break;
2807
2808 case 24:
2809 //lit + h flip
2810 //return an error, cannot both rotate and H flip
2811 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2812 break;
2813
2814 case 26:
2815 //pivot + lit + hflip
2816 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2817 //return error cannot pivot, lit, and flip
2818 break;
2819
2820 case 28:
2821 //lit + vh flip
2822 //return an error, cannot both rotate and VH flip
2823 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2824 break;
2825
2826 case 32: //gouraud
2827 //Probably not wort supporting.
2828 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2829 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2830 break;
2831
2832 case 0:
2833 //no effect.
2834 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2835 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2836 break;
2837
2838 default:
2839 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2840
2841 }
2842 }
2843 } //end if stretched and masked
2844
2845 else //stretched, not masked
2846 {
2847 if ( rot == 0 ) //if not rotated
2848 {
2849 switch(mode) {
2850 case 1:
2851 //transparent
2852 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2853 draw_trans_sprite(bmp, subBmp, dx, dy);
2854 break;
2855
2856
2857 case 2:
2858 //pivot?
2859 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2860 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2861 //Pivoting requires two more args
2862 break;
2863
2864 case 3:
2865 //pivot + trans
2866 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2867 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2868 break;
2869
2870 case 4:
2871 //flip v
2872 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2873 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2874 break;
2875
2876 case 5:
2877 //trans + v flip
2878 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2879 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2880 break;
2881
2882 case 6:
2883 //pivot + v flip
2884 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2885 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2886 break;
2887
2888 case 8:
2889 //vlip h
2890 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2891 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2892 break;
2893
2894 case 9:
2895 //trans + h flip
2896 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2897 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2898 break;
2899
2900 case 10:
2901 //flip H and pivot
2902 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2903 //return error cannot pivot and h flip
2904 break;
2905
2906 case 12:
2907 //vh flip
2908 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2909 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2910 break;
2911
2912 case 13:
2913 //trans + vh flip
2914 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2915 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2916 break;
2917
2918 case 14:
2919 //pivot and vh flip
2920 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2921 //return error cannot both pivot and vh flip
2922 break;
2923
2924 case 16:
2925 //lit
2926 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2927 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2928 break;
2929
2930 case 18:
2931 //pivot, lit
2932 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2933 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2934 break;
2935
2936 case 20:
2937 //lit + v flip
2938 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2939 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2940 break;
2941
2942 case 22:
2943 //Pivot, vflip, lit
2944 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2945 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2946 break;
2947
2948 case 24:
2949 //lit + h flip
2950 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2951 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2952 break;
2953
2954 case 26:
2955 //pivot + lit + hflip
2956 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2957 //return error cannot pivot, lit, and flip
2958 break;
2959
2960 case 28:
2961 //lit + vh flip
2962 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2963 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2964 break;
2965
2966 case 32: //gouraud
2967 //Probably not wort supporting.
2968 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2969 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2970 break;
2971
2972 case 0:
2973 //no effect
2974 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2975 break;
2976
2977
2978 default:
2979 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2980
2981
2982 }
2983 } //end if not rotated
2984
2985 if ( rot != 0 ) //if rotated
2986 {
2987 switch(mode)
2988 {
2989 case 1:
2990 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
2991 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2992
2993 break;
2994
2995 case 2:
2996 //pivot?
2997 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2998 //return an error, cannot both rotate and pivot
2999 break;
3000
3001 case 3:
3002 //pivot + trans
3003 //return an error, cannot both rotate and pivot
3004 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3005 break;
3006
3007 case 4:
3008 //flip v
3009 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3010 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3011 break;
3012
3013 case 5:
3014 //trans + v flip
3015 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3016 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3017 break;
3018
3019 case 6:
3020 //pivot + v flip
3021 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3022 //return an error, cannot both rotate and pivot
3023 break;
3024
3025 case 8:
3026 //flip h
3027 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3028 //return an error, cannot both rotate and flip H
3029 break;
3030
3031 case 9:
3032 //trans + h flip
3033 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3034 //return an error, cannot rotate and flip a trans sprite
3035 break;
3036
3037 case 10:
3038 //flip H and pivot
3039 //return error cannot pivot and h flip
3040 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3041 break;
3042
3043 case 12:
3044 //vh flip
3045 //return an error, cannot rotate and VH flip a trans sprite
3046 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3047 break;
3048
3049 case 13:
3050 //trans + vh flip
3051 //return an error, cannot rotate and VH flip a trans sprite
3052 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3053 break;
3054
3055 case 14:
3056 //pivot and vh flip
3057 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3058 //return error cannot both pivot and vh flip
3059 break;
3060
3061 case 16:
3062 //lit
3063 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3064 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3065 break;
3066
3067 case 18:
3068 //pivot, lit
3069 //return an error, cannot both rotate and pivot
3070 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3071 break;
3072
3073 case 20:
3074 //lit + vflip
3075 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3076 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3077 break;
3078
3079 case 22:
3080 //Pivot, vflip, lit
3081 //return an error, cannot both rotate and pivot
3082 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3083 break;
3084
3085 case 24:
3086 //lit + h flip
3087 //return an error, cannot both rotate and H flip
3088 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3089 break;
3090
3091 case 26:
3092 //pivot + lit + hflip
3093 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3094 //return error cannot pivot, lit, and flip
3095 break;
3096
3097 case 28:
3098 //lit + vh flip
3099 //return an error, cannot both rotate and VH flip
3100 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3101 break;
3102
3103 case 32: //gouraud
3104 //Probably not wort supporting.
3105 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3106 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3107 break;
3108
3109 case 0:
3110 //no effect.
3111 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3112 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3113 break;
3114
3115 default:
3116 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3117
3118 }
3119 }
3120
3121 } //end if stretched, but not masked
3122 }
3123 else //not stretched
3124 {
3125
3126 if(masked) //if masked, but not stretched
3127 {
3128
3129 if ( rot == 0 ) //if not rotated
3130 {
3131 switch(mode)
3132 {
3133 case 1:
3134 //transparent
3135 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3136 draw_trans_sprite(bmp, subBmp, dx, dy);
3137 break;
3138
3139
3140 case 2:
3141 //pivot?
3142 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3143 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3144 //Pivoting requires two more args
3145 break;
3146
3147 case 3:
3148 //pivot + trans
3149 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3150 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3151 break;
3152
3153 case 4:
3154 //flip v
3155 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3156 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3157 break;
3158
3159 case 5:
3160 //trans + v flip
3161 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3162 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3163 break;
3164
3165 case 6:
3166 //pivot + v flip
3167 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3168 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3169 break;
3170
3171 case 8:
3172 //vlip h
3173 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3174 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3175 break;
3176
3177 case 9:
3178 //trans + h flip
3179 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3180 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3181 break;
3182
3183 case 10:
3184 //flip H and pivot
3185 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3186 //return error cannot pivot and h flip
3187 break;
3188
3189 case 12:
3190 //vh flip
3191 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3192 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3193 break;
3194
3195 case 13:
3196 //trans + vh flip
3197 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3198 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3199 break;
3200
3201 case 14:
3202 //pivot and vh flip
3203 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3204 //return error cannot both pivot and vh flip
3205 break;
3206
3207 case 16:
3208 //lit
3209 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3210 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3211 break;
3212
3213 case 18:
3214 //pivot, lit
3215 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3216 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3217 break;
3218
3219 case 20:
3220 //lit + v flip
3221 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3222 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3223 break;
3224
3225 case 22:
3226 //Pivot, vflip, lit
3227 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3228 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3229 break;
3230
3231 case 24:
3232 //lit + h flip
3233 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3234 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3235 break;
3236
3237 case 26:
3238 //pivot + lit + hflip
3239 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3240 //return error cannot pivot, lit, and flip
3241 break;
3242
3243 case 28:
3244 //lit + vh flip
3245 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3246 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3247 break;
3248
3249 case 32: //gouraud
3250 //Probably not wort supporting.
3251 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3252 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3253 break;
3254
3255 case 0:
3256 //no effect
3257 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3258 break;
3259
3260
3261 default:
3262 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3263
3264
3265 }
3266 } //end if not rotated
3267
3268 if ( rot != 0 ) //if rotated
3269 {
3270 switch(mode)
3271 {
3272 case 1:
3273 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3274 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3275
3276 break;
3277
3278 case 2:
3279 //pivot?
3280 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3281 //return an error, cannot both rotate and pivot
3282 break;
3283
3284 case 3:
3285 //pivot + trans
3286 //return an error, cannot both rotate and pivot
3287 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3288 break;
3289
3290 case 4:
3291 //flip v
3292 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3293 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3294 break;
3295
3296 case 5:
3297 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3298 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3299 break;
3300
3301 case 6:
3302 //pivot + v flip
3303 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3304 //return an error, cannot both rotate and pivot
3305 break;
3306
3307 case 8:
3308 //flip h
3309 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3310 //return an error, cannot both rotate and flip H
3311 break;
3312
3313 case 9:
3314 //trans + h flip
3315 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3316 //return an error, cannot rotate and flip a trans sprite
3317 break;
3318
3319 case 10:
3320 //flip H and pivot
3321 //return error cannot pivot and h flip
3322 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3323 break;
3324
3325 case 12:
3326 //vh flip
3327 //return an error, cannot rotate and VH flip a trans sprite
3328 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3329 break;
3330
3331 case 13:
3332 //trans + vh flip
3333 //return an error, cannot rotate and VH flip a trans sprite
3334 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3335 break;
3336
3337 case 14:
3338 //pivot and vh flip
3339 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3340 //return error cannot both pivot and vh flip
3341 break;
3342
3343 case 16:
3344 //lit
3345 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3346 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3347 break;
3348
3349 case 18:
3350 //pivot, lit
3351 //return an error, cannot both rotate and pivot
3352 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3353 break;
3354
3355 case 20:
3356 //lit + vflip
3357 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3358 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3359 break;
3360
3361 case 22:
3362 //Pivot, vflip, lit
3363 //return an error, cannot both rotate and pivot
3364 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3365 break;
3366
3367 case 24:
3368 //lit + h flip
3369 //return an error, cannot both rotate and H flip
3370 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3371 break;
3372
3373 case 26:
3374 //pivot + lit + hflip
3375 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3376 //return error cannot pivot, lit, and flip
3377 break;
3378
3379 case 28:
3380 //lit + vh flip
3381 //return an error, cannot both rotate and VH flip
3382 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3383 break;
3384
3385 case 32: //gouraud
3386 //Probably not wort supporting.
3387 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3388 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3389 break;
3390
3391 case 0:
3392 //no effect.
3393 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3394 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3395 break;
3396
3397 default:
3398 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3399
3400 }
3401 } //end rtated, masked
3402 } //end if masked
3403
3404 else //not masked, and not stretched; just blit
3405 {
3406
3407 if ( rot == 0 ) //if not rotated
3408 {
3409 switch(mode)
3410 {
3411 case 1:
3412 //transparent
3413 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3414 draw_trans_sprite(bmp, subBmp, dx, dy);
3415 break;
3416
3417
3418 case 2:
3419 //pivot?
3420 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3421 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3422 //Pivoting requires two more args
3423 break;
3424
3425 case 3:
3426 //pivot + trans
3427 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3428 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3429 break;
3430
3431 case 4:
3432 //flip v
3433 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3434 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3435 break;
3436
3437 case 5:
3438 //trans + v flip
3439 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3440 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3441 break;
3442
3443 case 6:
3444 //pivot + v flip
3445 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3446 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3447 break;
3448
3449 case 8:
3450 //vlip h
3451 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3452 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3453 break;
3454
3455 case 9:
3456 //trans + h flip
3457 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3458 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3459 break;
3460
3461 case 10:
3462 //flip H and pivot
3463 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3464 //return error cannot pivot and h flip
3465 break;
3466
3467 case 12:
3468 //vh flip
3469 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3470 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3471 break;
3472
3473 case 13:
3474 //trans + vh flip
3475 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3476 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3477 break;
3478
3479 case 14:
3480 //pivot and vh flip
3481 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3482 //return error cannot both pivot and vh flip
3483 break;
3484
3485 case 16:
3486 //lit
3487 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3488 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3489 break;
3490
3491 case 18:
3492 //pivot, lit
3493 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3494 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3495 break;
3496
3497 case 20:
3498 //lit + v flip
3499 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3500 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3501 break;
3502
3503 case 22:
3504 //Pivot, vflip, lit
3505 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3506 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3507 break;
3508
3509 case 24:
3510 //lit + h flip
3511 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3512 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3513 break;
3514
3515 case 26:
3516 //pivot + lit + hflip
3517 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3518 //return error cannot pivot, lit, and flip
3519 break;
3520
3521 case 28:
3522 //lit + vh flip
3523 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3524 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3525 break;
3526
3527 case 32: //gouraud
3528 //Probably not wort supporting.
3529 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3530 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3531 break;
3532
3533 case 0:
3534 //no effect
3535 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3536 break;
3537
3538
3539 default:
3540 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3541
3542
3543 }
3544 } //end if not rotated
3545
3546 if ( rot != 0 ) //if rotated
3547 {
3548 switch(mode)
3549 {
3550 case 1:
3551 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3552 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3553
3554 break;
3555
3556 case 2:
3557 //pivot?
3558 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3559 //return an error, cannot both rotate and pivot
3560 break;
3561
3562 case 3:
3563 //pivot + trans
3564 //return an error, cannot both rotate and pivot
3565 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3566 break;
3567
3568 case 4:
3569 //flip v
3570 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3571 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3572 break;
3573
3574 case 5:
3575 //trans + v flip
3576 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3577 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3578 break;
3579
3580 case 6:
3581 //pivot + v flip
3582 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3583 //return an error, cannot both rotate and pivot
3584 break;
3585
3586 case 8:
3587 //flip h
3588 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3589 //return an error, cannot both rotate and flip H
3590 break;
3591
3592 case 9:
3593 //trans + h flip
3594 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3595 //return an error, cannot rotate and flip a trans sprite
3596 break;
3597
3598 case 10:
3599 //flip H and pivot
3600 //return error cannot pivot and h flip
3601 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3602 break;
3603
3604 case 12:
3605 //vh flip
3606 //return an error, cannot rotate and VH flip a trans sprite
3607 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3608 break;
3609
3610 case 13:
3611 //trans + vh flip
3612 //return an error, cannot rotate and VH flip a trans sprite
3613 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3614 break;
3615
3616 case 14:
3617 //pivot and vh flip
3618 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3619 //return error cannot both pivot and vh flip
3620 break;
3621
3622 case 16:
3623 //lit
3624 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3625 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3626 break;
3627
3628 case 18:
3629 //pivot, lit
3630 //return an error, cannot both rotate and pivot
3631 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3632 break;
3633
3634 case 20:
3635 //lit + vflip
3636 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3637 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3638 break;
3639
3640 case 22:
3641 //Pivot, vflip, lit
3642 //return an error, cannot both rotate and pivot
3643 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3644 break;
3645
3646 case 24:
3647 //lit + h flip
3648 //return an error, cannot both rotate and H flip
3649 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3650 break;
3651
3652 case 26:
3653 //pivot + lit + hflip
3654 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3655 //return error cannot pivot, lit, and flip
3656 break;
3657
3658 case 28:
3659 //lit + vh flip
3660 //return an error, cannot both rotate and VH flip
3661 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3662 break;
3663
3664 case 32: //gouraud
3665 //Probably not wort supporting.
3666 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3667 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3668 break;
3669
3670 case 0:
3671 //no effect.
3672 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3673 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3674 break;
3675
3676 default:
3677 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3678
3679 }
3680 } //end if rotated
3681 } //end if not masked
3682 } //end if not stretched
3683
3684 //cleanup
3685 if(subBmp)
3686 {
3687 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3688 }
3689 }
3690
3691
3692 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3693 {
3694 //sdci[1]=layer
3695 //sdci[2]=pos[12]
3696 //sdci[3]=uv[8]
3697 //sdci[4]=color[4]
3698 //sdci[5]=size[2]
3699 //sdci[6]=flip
3700 //sdci[7]=tile/combo
3701 //sdci[8]=polytype
3702
3703 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3704
3705 if(!v_ptr)
3706 {
3707 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3708 return;
3709 }
3710
3711 std::vector<int32_t> &v = *v_ptr;
3712
3713 if(v.empty())
3714 return;
3715
3716 int32_t* pos = &v[0];
3717 int32_t* uv = &v[12];
3718 int32_t* col = &v[20];
3719 int32_t* size = &v[24];
3720
3721 int32_t w = size[0]; //magic numerical constants... yuck.
3722 int32_t h = size[1];
3723 int32_t flip = (sdci[6]/10000)&3;
3724 int32_t tile = sdci[7]/10000;
3725 int32_t polytype = sdci[8]/10000;
3726
3727 polytype = vbound(polytype, 0, 14);
3728
3729 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3730 {
3731 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3732 return; //non power of two error
3733 }
3734
3735 int32_t tex_width = w*16;
3736 int32_t tex_height = h*16;
3737
3738 bool mustDestroyBmp = false;
3739 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3740
3741 if(!tex)
3742 {
3743 mustDestroyBmp = true;
3744 tex = create_bitmap_ex(8, tex_width, tex_height);
3745 clear_bitmap(tex);
3746 }
3747
3748 if(tile > 0) // TILE
3749 {
3750 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3751 }
3752 else // COMBO
3753 {
3754 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3755 const int32_t tiletodraw = combo_tile(c, 0, 0);
3756 flip = flip ^ c.flip;
3757
3758 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3759 }
3760
3761 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3762 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3763 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3764 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3765
3766 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3767
3768 if(mustDestroyBmp)
3769 destroy_bitmap(tex);
3770
3771 }
3772
3773
3774
3775 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3776 {
3777 //sdci[1]=layer
3778 //sdci[2]=pos[9]
3779 //sdci[3]=uv[6]
3780 //sdci[4]=color[3]
3781 //sdci[5]=size[2]
3782 //sdci[6]=flip
3783 //sdci[7]=tile/combo
3784 //sdci[8]=polytype
3785
3786 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3787
3788 if(!v_ptr)
3789 {
3790 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3791 return;
3792 }
3793
3794 std::vector<int32_t> &v = *v_ptr;
3795
3796 if(v.empty())
3797 return;
3798
3799 int32_t* pos = &v[0];
3800 int32_t* uv = &v[9];
3801 int32_t* col = &v[15];
3802 int32_t* size = &v[18];
3803
3804 int32_t w = size[0]; //magic numerical constants... yuck.
3805 int32_t h = size[1];
3806 int32_t flip = (sdci[6]/10000)&3;
3807 int32_t tile = sdci[7]/10000;
3808 int32_t polytype = sdci[8]/10000;
3809
3810 polytype = vbound(polytype, 0, 14);
3811
3812 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3813 {
3814 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3815 return; //non power of two error
3816 }
3817
3818 int32_t tex_width = w*16;
3819 int32_t tex_height = h*16;
3820
3821 bool mustDestroyBmp = false;
3822 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3823
3824 if(!tex)
3825 {
3826 mustDestroyBmp = true;
3827 tex = create_bitmap_ex(8, tex_width, tex_height);
3828 clear_bitmap(tex);
3829 }
3830
3831 if(tile > 0) // TILE
3832 {
3833 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3834 }
3835 else // COMBO
3836 {
3837 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3838 const int32_t tiletodraw = combo_tile(c, 0, 0);
3839 flip = flip ^ c.flip;
3840
3841 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3842 }
3843
3844 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3845 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3846 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3847
3848 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3849
3850 if(mustDestroyBmp)
3851 destroy_bitmap(tex);
3852
3853 }
3854
3855 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3856 {
3857 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3858 //sdci[1]=layer
3859 //sdci[2]=x
3860 //sdci[3]=y
3861 //sdci[4]=x2
3862 //sdci[5]=y2
3863 //sdci[6]=color
3864 //sdci[7]=scale factor
3865 //sdci[8]=rotation anchor x
3866 //sdci[9]=rotation anchor y
3867 //sdci[10]=rotation angle
3868 //sdci[11]=fill
3869 //sdci[12]=opacity
3870 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
3871
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3872 {
3873 return;
3874 }
3875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3876 {
3877 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3878 return;
3879 }
3880 7971 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
3881
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3882
3883
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3884
3885 7971 int32_t x1=sdci[2]/10000;
3886 7971 int32_t y1=sdci[3]/10000;
3887 7971 int32_t x2=sdci[4]/10000;
3888 7971 int32_t y2=sdci[5]/10000;
3889
3890
3891
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3892 {
3893 4 zc_swap(x1,x2);
3894 4 }
3895
3896
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3897 {
3898 4 zc_swap(y1,y2);
3899 4 }
3900
3901
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3902 {
3903 int32_t w=x2-x1+1;
3904 int32_t h=y2-y1+1;
3905 int32_t w2=(w*sdci[7])/10000;
3906 int32_t h2=(h*sdci[7])/10000;
3907 x1=x1-((w2-w)/2);
3908 x2=x2+((w2-w)/2);
3909 y1=y1-((h2-h)/2);
3910 y2=y2+((h2-h)/2);
3911 }
3912
3913 7971 int32_t color=sdci[6]/10000;
3914
3915
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3916 {
3917 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3918 128 }
3919
3920
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3921 {
3922
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
3923 {
3924 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3925 7863 }
3926 else //outline
3927 {
3928 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3929 }
3930 7875 }
3931 else //rotate
3932 {
3933 int32_t xy[16];
3934 96 int32_t rx=sdci[8]/10000;
3935 96 int32_t ry=sdci[9]/10000;
3936 96 fixed ra1=itofix(sdci[10]%10000)/10000;
3937 96 fixed ra2=itofix(sdci[10]/10000);
3938 96 fixed ra=ra1+ra2;
3939 96 ra = (ra/360)*256;
3940
3941 96 fixed fcosa = fixcos(ra);
3942 96 fixed fsina = fixsin(ra);
3943
3944 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
3945 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
3946 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
3947 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
3948 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
3949 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
3950 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
3951 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
3952 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
3953 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
3954 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
3955 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
3956 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
3957 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
3958 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
3959 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
3960
3961
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
3962 {
3963 96 polygon(refbmp, 4, xy, color);
3964 96 }
3965 else //outline
3966 {
3967 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
3968 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
3969 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
3970 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
3971 }
3972 }
3973
3974 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
3975 7971 }
3976
3977 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3978 {
3979 //sdci[1]=layer
3980 //sdci[2]=x
3981 //sdci[3]=y
3982 //sdci[4]=tile
3983 //sdci[5]=cset
3984 //sdci[6]=width
3985 //sdci[7]=height
3986 //sdci[8]=overlay
3987 //sdci[9]=opacity
3988
3989 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3990 {
3991 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3992 return;
3993 }
3994 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
3995 if ( refbmp == NULL ) return;
3996
3997 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3998
3999 int32_t x=sdci[2]/10000;
4000 int32_t y=sdci[3]/10000;
4001
4002 int32_t tile=sdci[4]/10000;
4003 int32_t cs=sdci[5]/10000;
4004 int32_t w=sdci[6]/10000;
4005 int32_t h=sdci[7]/10000;
4006 bool overlay=sdci[8];
4007 bool trans=(sdci[9]/10000<=127);
4008
4009 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4010 }
4011
4012
4013 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4014 {
4015 //sdci[1]=layer
4016 //sdci[2]=x
4017 //sdci[3]=y
4018 //sdci[4]=radius
4019 //sdci[5]=color
4020 //sdci[6]=scale factor
4021 //sdci[7]=rotation anchor x
4022 //sdci[8]=rotation anchor y
4023 //sdci[9]=rotation angle
4024 //sdci[10]=fill
4025 //sdci[11]=opacity
4026 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4027
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4028 {
4029 return;
4030 }
4031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4032 {
4033 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4034 return;
4035 }
4036 148823 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4037
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4038
4039
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4040
4041 148823 int32_t x1=sdci[2]/10000;
4042 148823 int32_t y1=sdci[3]/10000;
4043 148823 qword r=sdci[4];
4044
4045
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4046 {
4047 r*=sdci[6];
4048 r/=10000;
4049 }
4050
4051 148823 r/=10000;
4052 148823 int32_t color=sdci[5]/10000;
4053
4054
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4055 {
4056 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4057 }
4058
4059
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4060 {
4061 int32_t xy[2];
4062 int32_t rx=sdci[7]/10000;
4063 int32_t ry=sdci[8]/10000;
4064 fixed ra1=itofix(sdci[9]%10000)/10000;
4065 fixed ra2=itofix(sdci[9]/10000);
4066 fixed ra=ra1+ra2;
4067 ra = (ra/360)*256;
4068
4069 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4070 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4071 x1=xy[0];
4072 y1=xy[1];
4073 }
4074
4075
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4076 {
4077 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4078 148823 }
4079 else //outline
4080 {
4081 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4082 }
4083
4084 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4085 148823 }
4086
4087
4088 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4089 {
4090 //sdci[1]=layer
4091 //sdci[2]=x
4092 //sdci[3]=y
4093 //sdci[4]=radius
4094 //sdci[5]=start angle
4095 //sdci[6]=end angle
4096 //sdci[7]=color
4097 //sdci[8]=scale factor
4098 //sdci[9]=rotation anchor x
4099 //sdci[10]=rotation anchor y
4100 //sdci[11]=rotation angle
4101 //sdci[12]=closed
4102 //sdci[13]=fill
4103 //sdci[14]=opacity
4104 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4105
4106 if(sdci[8]==0) //scale
4107 {
4108 return;
4109 }
4110 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4111 {
4112 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4113 return;
4114 }
4115 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4116 if ( refbmp == NULL ) return;
4117
4118 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4119
4120 int32_t cx=sdci[2]/10000;
4121 int32_t cy=sdci[3]/10000;
4122 qword r=sdci[4];
4123
4124 if(sdci[8] != 10000)
4125 {
4126 r*=sdci[8];
4127 r/=10000;
4128 }
4129
4130 r/=10000;
4131
4132 int32_t color=sdci[7]/10000;
4133
4134 fixed ra1=itofix(sdci[11]%10000)/10000;
4135 fixed ra2=itofix(sdci[11]/10000);
4136 fixed ra=ra1+ra2;
4137 ra = (ra/360)*256;
4138
4139
4140 fixed a1=itofix(sdci[5]%10000)/10000;
4141 fixed a2=itofix(sdci[5]/10000);
4142 fixed sa=a1+a2;
4143 sa = (sa/360)*256;
4144
4145 a1=itofix(sdci[6]%10000)/10000;
4146 a2=itofix(sdci[6]/10000);
4147 fixed ea=a1+a2;
4148 ea = (ea/360)*256;
4149
4150 if(sdci[11]!=0) //rotation
4151 {
4152 int32_t rx=sdci[9]/10000;
4153 int32_t ry=sdci[10]/10000;
4154
4155 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4156 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4157 ea-=ra;
4158 sa-=ra;
4159 }
4160
4161 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4162 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4163
4164 if(sdci[12]) //closed
4165 {
4166 if(sdci[13]) //filled
4167 {
4168 clear_bitmap(prim_bmp);
4169 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4170 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4171 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4172 int fillx = zc_max(0,fx)+xoffset;
4173 int filly = zc_max(0,fy)+yoffset;
4174 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4175 floodfill(prim_bmp, fillx, filly, color);
4176
4177 if(sdci[14]/10000<=127) //translucent
4178 {
4179 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4180 }
4181 else
4182 {
4183 draw_sprite(refbmp, prim_bmp, 0,0);
4184 }
4185 }
4186 else
4187 {
4188 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4189 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4190 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4191 }
4192 }
4193 else
4194 {
4195 if(sdci[14]/10000<=127) //translucent
4196 {
4197 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4198 }
4199
4200 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4201 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4202 }
4203 }
4204
4205
4206 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4207 {
4208 //sdci[1]=layer
4209 //sdci[2]=x
4210 //sdci[3]=y
4211 //sdci[4]=radiusx
4212 //sdci[5]=radiusy
4213 //sdci[6]=color
4214 //sdci[7]=scale factor
4215 //sdci[8]=rotation anchor x
4216 //sdci[9]=rotation anchor y
4217 //sdci[10]=rotation angle
4218 //sdci[11]=fill
4219 //sdci[12]=opacity
4220 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4221
4222
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4223 {
4224 return;
4225 }
4226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4227 {
4228 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4229 return;
4230 }
4231 502 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4232
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4233
4234 502 int32_t x1=sdci[2]/10000;
4235 502 int32_t y1=sdci[3]/10000;
4236 502 int32_t radx=sdci[4]/10000;
4237 502 radx*=sdci[7]/10000;
4238 502 int32_t rady=sdci[5]/10000;
4239 502 rady*=sdci[7]/10000;
4240 502 int32_t color=sdci[6]/10000;
4241 502 float rotation = sdci[10]/10000;
4242
4243 502 int32_t rx=sdci[8]/10000;
4244 502 int32_t ry=sdci[9]/10000;
4245 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4246 502 fixed ra2=itofix(sdci[10]/10000);
4247 502 fixed ra=ra1+ra2;
4248 502 ra = (ra/360)*256;
4249
4250
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4251
4252 int32_t xy[2];
4253 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4254 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4255 502 x1=xy[0];
4256 502 y1=xy[1];
4257
4258
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4259
4260 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4261
4262
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4263
4264
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4265 {
4266
4267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4268 {
4269 clear_bitmap(prim_bmp);
4270 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4271 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4272 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4273 }
4274 else // no opacity
4275 {
4276
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4277 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4278 }
4279 494 }
4280 else //not filled
4281 {
4282 if(sdci[12]/10000<128) //translucent
4283 {
4284 clear_bitmap(prim_bmp);
4285 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4286 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4287 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4288 }
4289 else // no opacity
4290 {
4291 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4292 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4293 }
4294 }
4295
4296 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4297 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4298 // the ellipse, but it shouldn't be used anyway.
4299
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4300 {
4301 // This is very slow, so check the smallest possible square
4302
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4303
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4304
4305
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4306
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4307
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4308 233212 putpixel(refbmp, x, y, 0);
4309 62 }
4310
4311 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4312 502 }
4313
4314
4315 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4316 {
4317 //sdci[1]=layer
4318 //sdci[2]=x
4319 //sdci[3]=y
4320 //sdci[4]=x2
4321 //sdci[5]=y2
4322 //sdci[6]=color
4323 //sdci[7]=scale factor
4324 //sdci[8]=rotation anchor x
4325 //sdci[9]=rotation anchor y
4326 //sdci[10]=rotation angle
4327 //sdci[11]=opacity
4328 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4329
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4330 {
4331 return;
4332 }
4333
4334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4335 {
4336 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4337 return;
4338 }
4339
4340 144 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4341
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4342
4343 144 int32_t x1=sdci[2]/10000;
4344 144 int32_t y1=sdci[3]/10000;
4345 144 int32_t x2=sdci[4]/10000;
4346 144 int32_t y2=sdci[5]/10000;
4347
4348
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4349 {
4350 int32_t w=x2-x1+1;
4351 int32_t h=y2-y1+1;
4352 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4353 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4354 x1=x1-((w2-w)/2);
4355 x2=x2+((w2-w)/2);
4356 y1=y1-((h2-h)/2);
4357 y2=y2+((h2-h)/2);
4358 }
4359
4360 144 int32_t color=sdci[6]/10000;
4361
4362
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4363
4364
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4365 {
4366 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4367 }
4368
4369
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4370 {
4371 int32_t xy[4];
4372 int32_t rx=sdci[8]/10000;
4373 int32_t ry=sdci[9]/10000;
4374 fixed ra1=itofix(sdci[10]%10000)/10000;
4375 fixed ra2=itofix(sdci[10]/10000);
4376 fixed ra=ra1+ra2;
4377
4378 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4379 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4380 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4381 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4382 x1=xy[0];
4383 y1=xy[1];
4384 x2=xy[2];
4385 y2=xy[3];
4386 }
4387
4388 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4389 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4390 144 }
4391
4392
4393 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4394 {
4395 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4396 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4397
4398 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4399 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4400 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4401 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4402 };
4403
4404 if(sdci[11]/10000 < 128) //translucent
4405 {
4406 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4407 }
4408
4409 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4410 {
4411 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4412 return;
4413 }
4414
4415 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4416 if ( refbmp == NULL ) return;
4417
4418 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4419
4420 spline(refbmp, points, sdci[10]/10000);
4421
4422 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4423 }
4424
4425
4426 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4427 {
4428 //sdci[1]=layer
4429 //sdci[2]=x
4430 //sdci[3]=y
4431 //sdci[4]=color
4432 //sdci[5]=rotation anchor x
4433 //sdci[6]=rotation anchor y
4434 //sdci[7]=rotation angle
4435 //sdci[8]=opacity
4436 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4437 80910 int32_t x1=sdci[2]/10000;
4438 80910 int32_t y1=sdci[3]/10000;
4439 80910 int32_t color=sdci[4]/10000;
4440
4441
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4442 {
4443 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4444 }
4445
4446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4447 {
4448 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4449 return;
4450 }
4451
4452 80910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4453
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4454
4455
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4456
4457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4458 {
4459 int32_t xy[2];
4460 int32_t rx=sdci[5]/10000;
4461 int32_t ry=sdci[6]/10000;
4462 fixed ra1=itofix(sdci[7]%10000)/10000;
4463 fixed ra2=itofix(sdci[7]/10000);
4464 fixed ra=ra1+ra2;
4465
4466 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4467 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4468 x1=xy[0];
4469 y1=xy[1];
4470 }
4471
4472 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4473 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4474 80910 }
4475
4476
4477 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4478 {
4479 //sdci[1]=layer
4480 //sdci[2]=x
4481 //sdci[3]=y
4482 //sdci[4]=tile
4483 //sdci[5]=tile width
4484 //sdci[6]=tile height
4485 //sdci[7]=color (cset)
4486 //sdci[8]=scale x
4487 //sdci[9]=scale y
4488 //sdci[10]=rotation anchor x
4489 //sdci[11]=rotation anchor y
4490 //sdci[12]=rotation angle
4491 //sdci[13]=flip
4492 //sdci[14]=transparency
4493 //sdci[15]=opacity
4494 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4495
4496 59816 int32_t w = sdci[5]/10000;
4497 59816 int32_t h = sdci[6]/10000;
4498
4499
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4500 {
4501 return;
4502 }
4503
4504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4505 {
4506 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4507 return;
4508 }
4509
4510 59816 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4512
4513 59816 int32_t xscale=sdci[8]/10000;
4514 59816 int32_t yscale=sdci[9]/10000;
4515 59816 int32_t rx = sdci[10]/10000;
4516 59816 int32_t ry = sdci[11]/10000;
4517 59816 float rotation=sdci[12]/10000;
4518 59816 int32_t flip=(sdci[13]/10000)&3;
4519 59816 bool transparency=sdci[14]!=0;
4520 59816 int32_t opacity=sdci[15]/10000;
4521 59816 int32_t color=sdci[7]/10000;
4522
4523 59816 int32_t x1=sdci[2]/10000;
4524 59816 int32_t y1=sdci[3]/10000;
4525
4526
4527 //don't scale if it's not safe to do so
4528 59816 bool canscale = true;
4529
4530
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4531 {
4532 return;
4533 }
4534
4535
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4536 58910 canscale = false; //default size
4537
4538
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4539
4540
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4541 {
4542 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4543
4544
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4545 {
4546 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4547 5514 }
4548 else //no transparency
4549 {
4550 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4551 }
4552
4553
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4554 {
4555 //low negative values indicate no anchor-point rotation
4556
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4557 {
4558 int32_t xy[2];
4559 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4560 4608 fixed ra2=itofix(sdci[12]/10000);
4561 4608 fixed ra=ra1+ra2;
4562 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4563 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4564 4608 x1=xy[0];
4565 4608 y1=xy[1];
4566 4608 }
4567
4568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4569 {
4570 //damnit all, .. fixme.
4571 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4572 clear_bitmap(tempbit);
4573
4574 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4575
4576 if(opacity < 128)
4577 {
4578 clear_bitmap(prim_bmp);
4579 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4580 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4581 }
4582 else
4583 {
4584 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4585 }
4586
4587 destroy_bitmap(tempbit);
4588 }
4589 else //no scale
4590 {
4591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4592 {
4593 clear_bitmap(prim_bmp);
4594 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4595 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4596 }
4597 else
4598 {
4599 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4600 }
4601 }
4602 4608 }
4603 else //scale only
4604 {
4605
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4606 {
4607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4608 {
4609 clear_bitmap(prim_bmp);
4610 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4611 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4612 }
4613 else
4614 {
4615 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4616 }
4617 906 }
4618 else //error -do not scale
4619 {
4620 if(opacity<128)
4621 {
4622 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4623 }
4624 else
4625 {
4626 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4627 }
4628 }
4629 }
4630
4631 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4632
4633 5514 }
4634 else // no scale or rotation
4635 {
4636
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4637 {
4638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4639 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4640 else
4641 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4642 45964 }
4643 else
4644 {
4645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4646 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4647 else
4648 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4649 }
4650 }
4651 59816 }
4652
4653 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4654 {
4655 //sdci[1]=layer
4656 //sdci[2]=x
4657 //sdci[3]=y
4658 //sdci[4]=tile
4659 //sdci[5]=tile width
4660 //sdci[6]=tile height
4661 //sdci[7]=flip
4662 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4663
4664 int32_t w = sdci[5]/10000;
4665 int32_t h = sdci[6]/10000;
4666
4667 if(w < 1 || h < 1 || h > 20 || w > 20)
4668 {
4669 return;
4670 }
4671
4672 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4673 {
4674 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4675 return;
4676 }
4677
4678 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4679 if ( refbmp == NULL ) return;
4680
4681 int32_t flip=(sdci[7]/10000)&3;
4682
4683 int32_t x1=sdci[2]/10000;
4684 int32_t y1=sdci[3]/10000;
4685
4686 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4687
4688 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4689 }
4690
4691
4692 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4693 {
4694 //sdci[1]=layer
4695 //sdci[2]=x
4696 //sdci[3]=y
4697 //sdci[4]=combo
4698 //sdci[5]=tile width
4699 //sdci[6]=tile height
4700 //sdci[7]=color (cset)
4701 //sdci[8]=scale x
4702 //sdci[9]=scale y
4703 //sdci[10]=rotation anchor x
4704 //sdci[11]=rotation anchor y
4705 //sdci[12]=rotation angle
4706 //sdci[13]=frame
4707 //sdci[14]=flip
4708 //sdci[15]=transparency
4709 //sdci[16]=opacity
4710 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4711 824 int32_t w = sdci[5]/10000;
4712 824 int32_t h = sdci[6]/10000;
4713
4714
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4715 {
4716 return;
4717 }
4718
4719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4720 {
4721 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4722 return;
4723 }
4724
4725 824 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4726
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4727 824 int32_t cmb = (sdci[4]/10000);
4728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4729 {
4730 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4731 return;
4732 }
4733
4734 824 int32_t xscale=sdci[8]/10000;
4735 824 int32_t yscale=sdci[9]/10000;
4736 824 int32_t rx = sdci[10]/10000; //these work now
4737 824 int32_t ry = sdci[11]/10000; //these work now
4738 824 float rotation=sdci[12]/10000;
4739
4740 824 bool transparency=sdci[15]!=0;
4741 824 int32_t opacity=sdci[16]/10000;
4742 824 int32_t color=sdci[7]/10000;
4743 824 int32_t x1=sdci[2]/10000;
4744 824 int32_t y1=sdci[3]/10000;
4745
4746 824 const newcombo & c = combobuf[cmb];
4747 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4748 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4749 824 int32_t skiprows=c.skipanimy;
4750
4751
4752 //don't scale if it's not safe to do so
4753 824 bool canscale = true;
4754
4755
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4756 {
4757 return;
4758 }
4759
4760
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4761 824 canscale = false; //default size
4762
4763
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4764
4765
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4766 {
4767 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4768
4769 if(transparency)
4770 {
4771 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4772 }
4773 else //no transparency
4774 {
4775 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4776 }
4777
4778 if(rotation != 0) // rotate
4779 {
4780 //fixed point sucks ;0
4781 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4782 {
4783 int32_t xy[2];
4784 fixed ra1=itofix(sdci[12]%10000)/10000;
4785 fixed ra2=itofix(sdci[12]/10000);
4786 fixed ra=ra1+ra2;
4787 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4788 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4789 x1=xy[0];
4790 y1=xy[1];
4791 }
4792
4793 if(canscale) //scale first
4794 {
4795 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4796 clear_bitmap(tempbit);
4797
4798 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4799
4800 if(opacity < 128)
4801 {
4802 clear_bitmap(prim_bmp);
4803 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4804 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4805 }
4806 else
4807 {
4808 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4809 }
4810
4811 destroy_bitmap(tempbit);
4812 }
4813 else //no scale
4814 {
4815 if(opacity < 128)
4816 {
4817 clear_bitmap(prim_bmp);
4818 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4819 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4820 }
4821 else
4822 {
4823 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4824 }
4825 }
4826 }
4827 else //scale only
4828 {
4829 if(canscale)
4830 {
4831 if(opacity<128)
4832 {
4833 clear_bitmap(prim_bmp);
4834 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4835 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4836 }
4837 else
4838 {
4839 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4840 }
4841 }
4842 else //error -do not scale
4843 {
4844 if(opacity<128)
4845 {
4846 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4847 }
4848 else
4849 {
4850 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4851 }
4852 }
4853 }
4854
4855 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4856 }
4857 else // no scale or rotation
4858 {
4859
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4860 {
4861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4862 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4863 else
4864 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4865 824 }
4866 else
4867 {
4868 if(opacity<=127)
4869 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4870 else
4871 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4872 }
4873 }
4874 824 }
4875
4876
4877 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4878 {
4879 //sdci[1]=layer
4880 //sdci[2]=x
4881 //sdci[3]=y
4882 //sdci[4]=combo
4883 //sdci[5]=tile width
4884 //sdci[6]=tile height
4885 //sdci[7]=flip
4886 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4887
4888 int32_t w = sdci[5]/10000;
4889 int32_t h = sdci[6]/10000;
4890
4891 if(w<1||h<1||h>20||w>20)
4892 {
4893 return;
4894 }
4895
4896 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4897 {
4898 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4899 return;
4900 }
4901
4902 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4903 if ( refbmp == NULL ) return;
4904 int32_t cmb = (sdci[4]/10000);
4905 if((unsigned)cmb >= MAXCOMBOS)
4906 {
4907 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4908 return;
4909 }
4910
4911 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4912
4913 int32_t x1=sdci[2]/10000;
4914 int32_t y1=sdci[3]/10000;
4915
4916 const newcombo & c = combobuf[cmb];
4917 int32_t tiletodraw = combo_tile(c, x1, y1);
4918 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4919 int32_t skiprows=c.skipanimy;
4920
4921 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4922 }
4923
4924
4925 167483 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4926 {
4927 /* layer, x, y, tile, color opacity */
4928 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4929
4930 167483 int32_t opacity = sdci[6]/10000;
4931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167483 times.
167483 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4932 {
4933 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4934 return;
4935 }
4936 167483 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4937
1/2
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
167483 if ( refbmp == NULL ) return;
4938
4939
2/4
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167483 times.
✗ Branch 3 not taken.
167483 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4940
4941
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 156352 times.
167483 if(opacity < 128)
4942 11131 overtiletranslucent16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
4943 else
4944 156352 overtile16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
4945 167483 }
4946
4947 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4948 {
4949 /* layer, x, y, tile, is8bit, mask */
4950 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4952 {
4953 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4954 return;
4955 }
4956 19821648 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4957
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
4958
4959
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4960
4961 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
4962 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
4963
4964 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
4965 19821648 }
4966
4967 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4968 {
4969 /* layer, mask, color, ditherType, ditherArg */
4970 //sdci[2] Mask Bitmap Pointer
4971 //sdci[3] Color
4972 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4973 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4974 {
4975 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4976 return;
4977 }
4978 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4979 if ( refbmp == NULL ) return;
4980 if ( sdci[2] <= 0 )
4981 {
4982 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
4983 return;
4984 }
4985 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
4986 if ( mask == NULL ) return;
4987
4988 int32_t dType = sdci[4] / 10000L;
4989 if(dType < 0 || dType >= dithMax)
4990 {
4991 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
4992 return;
4993 }
4994
4995 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
4996 }
4997
4998 6363 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4999 {
5000 /* layer, shift, startcol, endcol */
5001 //sdci[2] NewCol
5002 //sdci[3] StartCol
5003 //sdci[4] EndCol
5004 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5006 {
5007 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5008 return;
5009 }
5010 6363 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( refbmp == NULL ) return;
5012 6363 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5013 6363 }
5014
5015 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5016 {
5017 /* layer, shift, startcol, endcol */
5018 //sdci[2] ShiftAmount
5019 //sdci[3] StartCol
5020 //sdci[4] EndCol
5021 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5022 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5023 {
5024 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5025 return;
5026 }
5027 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5028 if ( refbmp == NULL ) return;
5029 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5030 }
5031
5032 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5033 {
5034 /* layer, mask, color */
5035 //sdci[2] Mask Bitmap Pointer
5036 //sdci[3] Color
5037 //sdci[4] start mask color
5038 //sdci[5] end mask color
5039 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5040 906 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5041
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5042 {
5043 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5044 return;
5045 }
5046 906 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5047
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5048 {
5049 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5050 return;
5051 }
5052 906 auto fillcol = sdci[3]/10000L;
5053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5054 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5055 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5056 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5057 906 }
5058
5059 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5060 {
5061 /* layer, mask, color */
5062 //sdci[2] Mask Bitmap Pointer
5063 //sdci[3] Pattern Bitmap
5064 //sdci[4] bool 'pattern repeats'
5065 //sdci[5] start mask color
5066 //sdci[6] end mask color
5067 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5068 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5069 if ( refbmp == NULL )
5070 {
5071 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5072 return;
5073 }
5074 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5075 if ( mask == NULL )
5076 {
5077 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5078 return;
5079 }
5080 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]);
5081 if ( pattern == NULL )
5082 {
5083 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5084 return;
5085 }
5086 bool repeats = sdci[4]!=0;
5087 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5088 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5089 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5090 }
5091
5092 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5093 {
5094 /* layer, x, y, tile, color opacity */
5095 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5096 32636464 int32_t opacity = sdci[6] / 10000;
5097 32636464 int32_t x1 = sdci[2] / 10000;
5098 32636464 int32_t y1 = sdci[3] / 10000;
5099 32636464 int32_t index = sdci[4]/10000;
5100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5101 {
5102 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5103 return;
5104 }
5105 32636464 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5106
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5107 32636464 int32_t cmb = (sdci[4]/10000);
5108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5109 {
5110 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5111 return;
5112 }
5113
5114
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5115
5116 //if( index >= MAXCOMBOS ) return; //bleh.
5117 /*
5118 const newcombo & c = combobuf[index];
5119
5120 if(opacity < 128)
5121 overtiletranslucent16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
5122 else
5123 overtile16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
5124 */
5125
5126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5127 {
5128 overcomboblocktranslucent(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
5129
5130 }
5131 else
5132 {
5133 32636464 overcomboblock(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
5134 }
5135 32636464 }
5136
5137
5138
5139 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5140 {
5141 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5142 {
5143 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5144 return;
5145 }
5146 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5147 if ( refbmp == NULL ) return;
5148
5149 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5150
5151 //broken 2.50.2 and earlier drawcharacter()
5152 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5153 {
5154 //sdci[1]=layer
5155 //sdci[2]=x
5156 //sdci[3]=y
5157 //sdci[4]=font
5158 //sdci[5]=color
5159 //sdci[6]=bg color
5160 //sdci[7]=strech x (width)
5161 //sdci[8]=stretch y (height)
5162 //sdci[9]=char
5163 //sdci[10]=opacity
5164 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5165
5166 int32_t x=sdci[2]/10000;
5167 int32_t y=sdci[3]/10000;
5168 int32_t font_index=sdci[4]/10000;
5169 int32_t color=sdci[5]/10000;
5170 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5171 int32_t w=sdci[7]/10000;
5172 int32_t h=sdci[8]/10000;
5173 char glyph=char(sdci[9]/10000);
5174 int32_t opacity=sdci[10]/10000;
5175
5176 //safe check
5177 if(bg_color < -1) bg_color = -1;
5178
5179 if(w>512) w=512; //w=vbound(w,0,512);
5180
5181 if(h>512) h=512; //h=vbound(h,0,512);
5182
5183 //undone
5184 if(w>0&&h>0)//stretch the character
5185 {
5186 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5187
5188 if(opacity < 128)
5189 {
5190 if(w>128||h>128)
5191 {
5192 clear_bitmap(prim_bmp);
5193
5194 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5195 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5196 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5197 }
5198 else //this is faster
5199 {
5200 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5201
5202 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5203 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5204 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5205
5206 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5207 }
5208 }
5209 else // no opacity
5210 {
5211 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5212 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5213 }
5214
5215 }
5216 else //no stretch
5217 {
5218 if(opacity < 128)
5219 {
5220 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5221 clear_bitmap(pbmp);
5222
5223 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5224 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5225
5226 destroy_bitmap(pbmp);
5227 }
5228 else // no opacity
5229 {
5230 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5231 }
5232 }
5233 }
5234
5235 else //2.53.0 fixed version and later.
5236 {
5237
5238 //sdci[1]=layer
5239 //sdci[2]=x
5240 //sdci[3]=y
5241 //sdci[4]=font
5242 //sdci[5]=color
5243 //sdci[6]=bg color
5244 //sdci[7]=strech x (width)
5245 //sdci[8]=stretch y (height)
5246 //sdci[9]=char
5247 //sdci[10]=opacity
5248
5249 int32_t x=sdci[2]/10000;
5250 int32_t y=sdci[3]/10000;
5251 int32_t font_index=sdci[4]/10000;
5252 int32_t color=sdci[5]/10000;
5253 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5254 int32_t w=sdci[7]/10000;
5255 int32_t h=sdci[8]/10000;
5256 char glyph=char(sdci[9]/10000);
5257 int32_t opacity=sdci[10]/10000;
5258
5259 //safe check
5260 if(bg_color < -1) bg_color = -1;
5261
5262 if(w>512) w=512; //w=vbound(w,0,512);
5263
5264 if(h>512) h=512; //h=vbound(h,0,512);
5265
5266 //undone
5267 if(w>0&&h>0)//stretch the character
5268 {
5269 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5270
5271 if(opacity < 128)
5272 {
5273 if(w>128||h>128)
5274 {
5275 clear_bitmap(prim_bmp);
5276
5277 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5278 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5279 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5280 }
5281 else //this is faster
5282 {
5283 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5284
5285 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5286 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5287 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5288
5289 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5290 }
5291 }
5292 else // no opacity
5293 {
5294 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5295 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5296 }
5297
5298 }
5299 else //no stretch
5300 {
5301 if(opacity < 128)
5302 {
5303 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5304 clear_bitmap(pbmp);
5305
5306 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5307 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5308
5309 destroy_bitmap(pbmp);
5310 }
5311 else // no opacity
5312 {
5313 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5314 }
5315 }
5316
5317 }
5318
5319 }
5320
5321
5322 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5323 {
5324 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5325 {
5326 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5327 return;
5328 }
5329 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5330 if ( refbmp == NULL ) return;
5331
5332 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5333
5334 //broken 2.50.2 and earlier drawinteger()
5335 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5336 {
5337 //sdci[1]=layer
5338 //sdci[2]=x
5339 //sdci[3]=y
5340 //sdci[4]=font
5341 //sdci[5]=color
5342 //sdci[6]=bg color
5343 //sdci[7]=strech x (width)
5344 //sdci[8]=stretch y (height)
5345 //sdci[9]=integer
5346 //sdci[10]=num decimal places
5347 //sdci[11]=opacity
5348 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5349
5350 int32_t x=sdci[2]/10000;
5351 int32_t y=sdci[3]/10000;
5352 int32_t font_index=sdci[4]/10000;
5353 int32_t color=sdci[5]/10000;
5354 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5355 int32_t w=sdci[7]/10000;
5356 int32_t h=sdci[8]/10000;
5357 int32_t decplace=sdci[10]/10000;
5358 int32_t opacity=sdci[11]/10000;
5359
5360 //safe check
5361 if(bg_color < -1) bg_color = -1;
5362
5363 if(w>512) w=512; //w=vbound(w,0,512);
5364
5365 if(h>512) h=512; //h=vbound(h,0,512);
5366
5367 char numbuf[15];
5368
5369 switch(decplace)
5370 {
5371 default:
5372 case 0:
5373 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5374 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5375
5376 case 1:
5377 //sprintf(numbuf,"%.01f",number);
5378 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5379 break;
5380
5381 case 2:
5382 //sprintf(numbuf,"%.02f",number);
5383 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5384 break;
5385
5386 case 3:
5387 //sprintf(numbuf,"%.03f",number);
5388 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5389 break;
5390
5391 case 4:
5392 //sprintf(numbuf,"%.04f",number);
5393 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5394 break;
5395 }
5396
5397 if(w>0&&h>0)//stretch
5398 {
5399 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5400
5401 if(opacity < 128)
5402 {
5403 if(w>128||h>128)
5404 {
5405 clear_bitmap(prim_bmp);
5406
5407 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5408 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5409 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5410 }
5411 else
5412 {
5413 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5414 clear_bitmap(pbmp2);
5415
5416 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5417 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5418 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5419
5420 destroy_bitmap(pbmp2);
5421 }
5422 }
5423 else // no opacity
5424 {
5425 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5426 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5427 }
5428
5429 }
5430 else //no stretch
5431 {
5432 if(opacity < 128)
5433 {
5434 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5435 clear_bitmap(pbmp);
5436
5437 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5438 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5439
5440 destroy_bitmap(pbmp);
5441 }
5442 else // no opacity
5443 {
5444 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5445 }
5446 }
5447
5448 }
5449
5450 else //2.53.0 fixed version and later.
5451 {
5452 //sdci[1]=layer
5453 //sdci[2]=x
5454 //sdci[3]=y
5455 //sdci[4]=font
5456 //sdci[5]=color
5457 //sdci[6]=bg color
5458 //sdci[7]=strech x (width)
5459 //sdci[8]=stretch y (height)
5460 //sdci[9]=integer
5461 //sdci[10]=num decimal places
5462 //sdci[11]=opacity
5463
5464 int32_t x=sdci[2]/10000;
5465 int32_t y=sdci[3]/10000;
5466 int32_t font_index=sdci[4]/10000;
5467 int32_t color=sdci[5]/10000;
5468 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5469 int32_t w=sdci[7]/10000;
5470 int32_t h=sdci[8]/10000;
5471 int32_t decplace=sdci[10]/10000;
5472 int32_t opacity=sdci[11]/10000;
5473
5474 //safe check
5475 if(bg_color < -1) bg_color = -1;
5476
5477 if(w>512) w=512; //w=vbound(w,0,512);
5478
5479 if(h>512) h=512; //h=vbound(h,0,512);
5480
5481 char numbuf[15];
5482
5483 switch(decplace)
5484 {
5485 default:
5486 case 0:
5487 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5488 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5489
5490 case 1:
5491 //sprintf(numbuf,"%.01f",number);
5492 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5493 break;
5494
5495 case 2:
5496 //sprintf(numbuf,"%.02f",number);
5497 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5498 break;
5499
5500 case 3:
5501 //sprintf(numbuf,"%.03f",number);
5502 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5503 break;
5504
5505 case 4:
5506 //sprintf(numbuf,"%.04f",number);
5507 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5508 break;
5509 }
5510
5511 //FONT* font=get_zc_font(sdci[4]/10000);
5512
5513 if(w>0&&h>0)//stretch
5514 {
5515 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5516 clear_bitmap(pbmp);
5517 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5518
5519 if(opacity < 128)
5520 {
5521 if(w>128||h>128)
5522 {
5523 clear_bitmap(prim_bmp);
5524
5525 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5526 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5527 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5528 }
5529 else
5530 {
5531 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5532 clear_bitmap(pbmp2);
5533
5534 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5535 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5536 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5537
5538 destroy_bitmap(pbmp2);
5539 }
5540 }
5541 else // no opacity
5542 {
5543 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5544 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5545 }
5546
5547 }
5548 else //no stretch
5549 {
5550 if(opacity < 128)
5551 {
5552 FONT* font = get_zc_font(font_index);
5553 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5554 clear_bitmap(pbmp);
5555
5556 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5557 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5558
5559 destroy_bitmap(pbmp);
5560 }
5561 else // no opacity
5562 {
5563 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5564 }
5565 }
5566 }
5567 }
5568
5569
5570 855 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5571 {
5572 //sdci[1]=layer
5573 //sdci[2]=x
5574 //sdci[3]=y
5575 //sdci[4]=font
5576 //sdci[5]=color
5577 //sdci[6]=bg color
5578 //sdci[7]=format_option
5579 //sdci[8]=string
5580 //sdci[9]=opacity
5581 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5583 {
5584 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5585 return;
5586 }
5587
5588 855 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5589
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if ( refbmp == NULL ) return;
5590
5591
2/4
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 855 times.
855 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5592
5593 855 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5594
5595
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if(!str)
5596 {
5597 al_trace("String pointer is null! Internal error. \n");
5598 return;
5599 }
5600
5601 855 int32_t x=sdci[2]/10000;
5602 855 int32_t y=sdci[3]/10000;
5603 855 FONT* font=get_zc_font(sdci[4]/10000);
5604 855 int32_t color=sdci[5]/10000;
5605 855 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5606 855 int32_t format_type=sdci[7]/10000;
5607 855 int32_t opacity=sdci[9]/10000;
5608 //sdci[8] not needed :)
5609
5610 //safe check
5611
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if(bg_color < -1) bg_color = -1;
5612
5613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if(opacity < 128)
5614 {
5615 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5616 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5617 clear_bitmap(pbmp);
5618 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5619 if(format_type == 2) // right-sided text
5620 x-=width;
5621 else if(format_type == 1) // centered text
5622 x-=width/2;
5623 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5624 destroy_bitmap(pbmp);
5625 }
5626 else // no opacity
5627 {
5628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if(format_type == 2) // right-sided text
5629 {
5630 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5631 }
5632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 else if(format_type == 1) // centered text
5633 {
5634 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5635 }
5636 else // standard left-sided text
5637 {
5638 855 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5639 }
5640 }
5641 855 }
5642
5643 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5644 {
5645 //sdci[1]=layer
5646 //sdci[2]=x
5647 //sdci[3]=y
5648 //sdci[4]=font
5649 //sdci[5]=color
5650 //sdci[6]=bg color
5651 //sdci[7]=format_option
5652 //sdci[8]=string
5653 //sdci[9]=opacity
5654 //sdci[10]=shadowtype
5655 //sdci[11]=shadow_color
5656 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5658 {
5659 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5660 return;
5661 }
5662
5663 45504 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5664
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5665
5666
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5667
5668 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5669
5670
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5671 {
5672 al_trace("String pointer is null! Internal error. \n");
5673 return;
5674 }
5675
5676 45504 int32_t x=sdci[2]/10000;
5677 45504 int32_t y=sdci[3]/10000;
5678 45504 FONT* font=get_zc_font(sdci[4]/10000);
5679 45504 int32_t color=sdci[5]/10000;
5680 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5681 45504 int32_t format_type=sdci[7]/10000;
5682 45504 int32_t opacity=sdci[9]/10000;
5683 45504 int32_t textstyle = sdci[10]/10000;
5684 45504 int32_t shadow_color = sdci[11]/10000;
5685 //sdci[8] not needed :)
5686
5687 //safe check
5688
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5689
5690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5691 {
5692 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5693 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5694 clear_bitmap(pbmp);
5695 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5696 if(format_type == 2) // right-sided text
5697 x-=width;
5698 else if(format_type == 1) // centered text
5699 x-=width/2;
5700 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5701 destroy_bitmap(pbmp);
5702 }
5703 else // no opacity
5704 {
5705 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5706 }
5707 45504 }
5708
5709 324163 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5710 {
5711
1/2
✓ Branch 0 taken 324163 times.
✗ Branch 1 not taken.
324163 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5712 {
5713 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5714 return;
5715 }
5716 324163 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5717 324163 auto& usr_bitmap = scb.get(bitid);
5718
1/2
✓ Branch 0 taken 324163 times.
✗ Branch 1 not taken.
324163 if (usr_bitmap.u_bmp)
5719 324163 clear_bitmap(usr_bitmap.u_bmp);
5720 324163 }
5721
5722 2790 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5723 {
5724 //sdci[1]=layer
5725 //sdci[2]=color
5726 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5727 2790 int32_t pal_color = sdci[2]/10000;
5728
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5729 {
5730 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5731 return;
5732 }
5733 2790 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5734 2790 auto& usr_bitmap = scb.get(bitid);
5735
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if (usr_bitmap.u_bmp)
5736 2790 clear_to_color(usr_bitmap.u_bmp, pal_color);
5737 2790 }
5738
5739
5740 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5741 {
5742 //sdci[1]=layer
5743 34653 int32_t h = sdci[3]/10000;
5744 34653 int32_t w = sdci[2]/10000;
5745
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5746 {
5747 //flip height and width
5748 h = h ^ w;
5749 w = h ^ w;
5750 h = h ^ w;
5751 }
5752 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5753 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5755 {
5756 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5757 return;
5758 }
5759 34653 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5760 34653 auto& usr_bmp = scb.get(bitid);
5761
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5762 34528 destroy_bitmap(usr_bmp.u_bmp);
5763 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5764
5765 34653 usr_bmp.width = w;
5766 34653 usr_bmp.height = h;
5767 34653 }
5768
5769 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5770 {
5771 //sdci[1]=layer
5772 //sdci[2]=filename
5773 //sdci[3]=y
5774 //sdci[4]=font
5775 //sdci[5]=color
5776 //sdci[6]=bg color
5777 //sdci[7]=format_option
5778 //sdci[8]=string
5779 //sdci[9]=opacity
5780 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5781 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5782 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5783 {
5784 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5785 return;
5786 }
5787 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5788 auto& usr_bitmap = scb.get(bitid);
5789 usr_bitmap.destroy();
5790
5791 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5792
5793 if(!str)
5794 {
5795 al_trace("String pointer is null! Internal error. \n");
5796 return;
5797 }
5798
5799 PALETTE tempPal;
5800 get_palette(tempPal);
5801 if ( checkPath(str->c_str(), false) )
5802 {
5803 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5804 usr_bitmap.width = usr_bitmap.u_bmp->w;
5805 usr_bitmap.height = usr_bitmap.u_bmp->h;
5806 if ( !usr_bitmap.u_bmp )
5807 {
5808 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5809 }
5810 else
5811 {
5812 zprint("Read image file %s\n",str->c_str());
5813 }
5814 }
5815 else
5816 {
5817 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5818 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5819 clear_bitmap(usr_bitmap.u_bmp);
5820 }
5821 }
5822
5823
5824
5825 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5826 {
5827 //sdci[1]=layer
5828 //sdci[2]=filename
5829 //sdci[3]=y
5830 //sdci[4]=font
5831 //sdci[5]=color
5832 //sdci[6]=bg color
5833 //sdci[7]=format_option
5834 //sdci[8]=string
5835 //sdci[9]=opacity
5836 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5837 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5838
5839 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5840 {
5841 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5842 return;
5843 }
5844 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5845 auto& usr_bitmap = scb.get(bitid);
5846 if (!usr_bitmap.u_bmp)
5847 {
5848 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[DRAWCMD_BMP_TARGET]);
5849 return;
5850 }
5851
5852 bool overwrite = (sdci[3] != 0);
5853 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5854
5855 if(!str)
5856 {
5857 al_trace("String pointer is null! Internal error. \n");
5858 return;
5859 }
5860
5861 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5862 //std::strncpy(cptr, str->c_str(), str->size());
5863 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5864 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5865 if
5866 (
5867 ( (FFCore.checkExtension(*str, "")) ) ||
5868 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5869 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5870 )
5871 {
5872 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5873 }
5874 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5875 {
5876 if(create_path(str->c_str()))
5877 {
5878 save_bitmap(str->c_str(), usr_bitmap.u_bmp, RAMpal);
5879 if(checkPath(str->c_str(), false))
5880 {
5881 zprint("Wrote image file %s\n",str->c_str());
5882 }
5883 else
5884 {
5885 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5886 }
5887 }
5888 else
5889 {
5890 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5891 }
5892 }
5893 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5894 }
5895
5896
5897 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5898 {
5899 //sdci[1]=layer
5900 //sdci[2]=x1
5901 //sdci[3]=y1
5902 //sdci[4]=x2
5903 //sdci[5]=y2
5904 //sdci[6]=x3
5905 //sdci[7]=y3
5906 //sdci[8]=x4
5907 //sdci[9]=y4
5908 //sdci[10]=width
5909 //sdci[11]=height
5910 //sdci[12]=cset
5911 //sdci[13]=flip
5912 //sdci[14]=tile/combo
5913 //sdci[15]=polytype
5914 //sdci[16] = other bitmap as texture
5915 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5916 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5917 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5918 {
5919 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5920 return;
5921 }
5922 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5923
5924 if ( !refbmp ) return;
5925
5926 int32_t x1 = sdci[2]/10000;
5927 int32_t y1 = sdci[3]/10000;
5928 int32_t x2 = sdci[4]/10000;
5929 int32_t y2 = sdci[5]/10000;
5930 int32_t x3 = sdci[6]/10000;
5931 int32_t y3 = sdci[7]/10000;
5932 int32_t x4 = sdci[8]/10000;
5933 int32_t y4 = sdci[9]/10000;
5934 int32_t w = sdci[10]/10000;
5935 int32_t h = sdci[11]/10000;
5936 int32_t color = sdci[12]/10000;
5937 int32_t flip=(sdci[13]/10000)&3;
5938 int32_t tile = sdci[14]/10000;
5939 int32_t polytype = sdci[15]/10000;
5940 int32_t quad_render_source = sdci[16];
5941 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
5942
5943 bool tex_is_bitmap = ( sdci[16] != 0 );
5944
5945 BITMAP *bmptexture=NULL;
5946 BITMAP *tex=NULL;
5947 polytype = vbound(polytype, 0, 14);
5948
5949 int32_t col[4];
5950 col[0]=col[1]=col[2]=col[3]=color;
5951 bool mustDestroyBmp = false;
5952
5953 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5954
5955 if ( tex_is_bitmap )
5956 {
5957 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
5958 if ( !bmptexture )
5959 {
5960 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
5961 tex_is_bitmap = 0;
5962 }
5963 }
5964
5965 if ( tex_is_bitmap )
5966 {
5967
5968 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5969 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5970 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
5971 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
5972
5973 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
5974 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
5975 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
5976 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
5977
5978 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
5979 }
5980 else
5981 {
5982 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
5983 if(!tex)
5984 {
5985 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
5986 mustDestroyBmp = true;
5987 tex = create_bitmap_ex(8, w*16, h*16);
5988 clear_bitmap(tex);
5989 }
5990
5991 if(tile > 0) // TILE
5992 {
5993 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
5994 }
5995
5996 if ( tile < 0 ) // COMBO
5997 {
5998 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
5999 const int32_t tiletodraw = combo_tile(c, x1, y1);
6000 flip = flip ^ c.flip;
6001
6002 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6003 }
6004 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6005 {
6006 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6007 return; //non power of two error
6008 }
6009 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6010 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6011 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6012 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6013 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6014
6015 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6016
6017 }
6018
6019
6020
6021
6022 //todo: finish palette shading
6023 /*
6024 POLYTYPE_FLAT
6025 POLYTYPE_GCOL
6026 POLYTYPE_GRGB
6027 POLYTYPE_ATEX
6028 POLYTYPE_PTEX
6029 POLYTYPE_ATEX_MASK
6030 POLYTYPE_PTEX_MASK
6031 POLYTYPE_ATEX_LIT
6032 POLYTYPE_PTEX_LIT
6033 POLYTYPE_ATEX_MASK_LIT
6034 POLYTYPE_PTEX_MASK_LIT
6035 POLYTYPE_ATEX_TRANS
6036 POLYTYPE_PTEX_TRANS
6037 POLYTYPE_ATEX_MASK_TRANS
6038 POLYTYPE_PTEX_MASK_TRANS
6039 */
6040
6041 if(mustDestroyBmp)
6042 destroy_bitmap(tex);
6043
6044 }
6045
6046
6047 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6048 {
6049 //sdci[1]=layer
6050 //sdci[2]=x1
6051 //sdci[3]=y1
6052
6053 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6054 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6055 {
6056 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6057 return;
6058 }
6059 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6060 if ( refbmp == NULL ) return;
6061
6062
6063 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6064
6065 int32_t x1 = sdci[2]/10000;
6066 int32_t y1 = (sdci[3]/10000)+yoffset;
6067 int32_t col = getpixel(scb.get(sdci[DRAWCMD_BMP_TARGET]).u_bmp, x1, y1);
6068 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6069 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[DRAWCMD_BMP_TARGET]));
6070 FFCore.set_sarg1(col);
6071 }
6072
6073
6074
6075
6076 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6077 {
6078 //sdci[1]=layer
6079 //sdci[2]=x1
6080 //sdci[3]=y1
6081 //sdci[4]=x2
6082 //sdci[5]=y2
6083 //sdci[6]=x3
6084 //sdci[7]=y3
6085 //sdci[8]=width
6086 //sdci[9]=height
6087 //sdci[10]=cset
6088 //sdci[11]=flip
6089 //sdci[12]=tile/combo
6090 //sdci[13]=polytype
6091 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6092 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6093 {
6094 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6095 return;
6096 }
6097 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6098 if ( refbmp == NULL ) return;
6099
6100
6101 int32_t render_source = sdci[14];
6102 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6103
6104 bool tex_is_bitmap = ( sdci[14] != 0 );
6105
6106 BITMAP *bmptexture=NULL;
6107 if ( tex_is_bitmap )
6108 {
6109 bmptexture = FFCore.GetScriptBitmap(render_source);
6110 if ( !bmptexture )
6111 {
6112 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6113 tex_is_bitmap = 0;
6114 }
6115 }
6116
6117 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6118
6119 int32_t x1 = sdci[2]/10000;
6120 int32_t y1 = sdci[3]/10000;
6121 int32_t x2 = sdci[4]/10000;
6122 int32_t y2 = sdci[5]/10000;
6123 int32_t x3 = sdci[6]/10000;
6124 int32_t y3 = sdci[7]/10000;
6125 int32_t w = sdci[8]/10000;
6126 int32_t h = sdci[9]/10000;
6127 int32_t color = sdci[10]/10000;
6128 int32_t flip=(sdci[11]/10000)&3;
6129 int32_t tile = sdci[12]/10000;
6130 int32_t polytype = sdci[13]/10000;
6131
6132 polytype = vbound(polytype, 0, 14);
6133 int32_t utex_w = w;
6134 int32_t utex_h = h;
6135
6136
6137 int32_t tex_width = w*16;
6138 int32_t tex_height = h*16;
6139
6140 bool mustDestroyBmp = false;
6141 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6142
6143 if(!tex)
6144 {
6145 mustDestroyBmp = true;
6146 tex = create_bitmap_ex(8, tex_width, tex_height);
6147 clear_bitmap(tex);
6148 }
6149
6150 int32_t col[3];
6151 /*
6152 if( color < 0 )
6153 {
6154 col[0]=draw_container.color_buffer[0];
6155 col[1]=draw_container.color_buffer[1];
6156 col[2]=draw_container.color_buffer[2];
6157 }
6158 else */
6159 {
6160 col[0]=col[1]=col[2]=color;
6161 }
6162
6163 if(tile > 0) // TILE
6164 {
6165 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6166 }
6167 else // COMBO
6168 {
6169 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6170 const int32_t tiletodraw = combo_tile(c, x1, y1);
6171 flip = flip ^ c.flip;
6172
6173 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6174 }
6175 if ( !tex_is_bitmap )
6176 {
6177 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6178 {
6179 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6180 return; //non power of two error
6181 }
6182 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6183 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6184 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6185
6186
6187 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6188
6189 }
6190
6191 else
6192 {
6193 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6194 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6195 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6196 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6197
6198 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6199 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6200 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6201
6202
6203 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6204
6205 }
6206
6207 if(mustDestroyBmp)
6208 destroy_bitmap(tex);
6209 }
6210
6211
6212 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6213 {
6214 /*
6215 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6216 int32_t scale_x, int32_t scale_y){
6217
6218 //sdci[1]=layer
6219 //sdci[2]=bitmap target
6220 //
6221 // -2 is the current Render Target
6222 // -1, this is the screen (framebuf).
6223 // 0: Render target 0
6224 // 1: Render target 1
6225 // 2: Render target 2
6226 // 3: Render target 3
6227 // 4: Render target 4
6228 // 5: Render target 5
6229 // 6: Render target 6
6230 // Otherwise: The pointer to a bitmap.
6231
6232 //sdci[3]=sourcex
6233 //sdci[4]=sourcey
6234 //sdci[5]=sourcew
6235 //sdci[6]=sourceh
6236
6237 //sdci[7]=destw
6238 //sdci[8]=desth
6239 //sdci[9]=angle
6240 //scdi[10] = pivot cx
6241 //sdci[11] = pivot cy
6242 //sdci[12] = space Z
6243 //sdci[13] = horizon
6244 //scdi[14] = scale X
6245 //scdi[15] = scale Y
6246 //sdci[16] = masked?
6247 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6248
6249
6250
6251 // ZScript-side constant values:
6252 const int32_t BITDX_NORMAL = 0;
6253 const int32_t BITDX_TRANS = 1; //Translucent
6254 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6255 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6256 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6257 //Note: Some modes cannot be combined. if a combination is not supported, an error
6258 // detailing this will be shown in allegro.log.
6259
6260 //scdi[15] = litcolour
6261 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6262 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6263
6264 //sdci[16]=mask
6265
6266 */
6267
6268
6269 int32_t bitmapIndex = sdci[2];
6270 int32_t usr_bitmap_index = sdci[2];
6271 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6272 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6273
6274 if ( bitmapIndex >= 10000 )
6275 {
6276 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6277 }
6278 else if ( usr_bitmap_index > 0 )
6279 {
6280 bitmapIndex = usr_bitmap_index;
6281 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6282 yoffset = 0;
6283 }
6284
6285 //rendering mode 7 args
6286 double srcX = sdci[3]/10000.0;
6287 double srcY = sdci[4]/10000.0;
6288 double destX = sdci[5]/10000.0;
6289 double destY = sdci[6]/10000.0;
6290
6291 double destW = sdci[7]/10000.0;
6292 double destH = sdci[8]/10000.0;
6293 double space_z = sdci[9]/10000.0;
6294 double horizon = sdci[10]/10000.0;
6295 double scale_x = sdci[11]/10000.0;
6296 double scale_y = sdci[12]/10000.0;
6297 byte masked = ( sdci[13] ) ? 1 : 0;
6298
6299
6300 int32_t ref = 0;
6301
6302 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6303 //Do we need to also check the render target and do the same thing if the
6304 //dest == -2 and the render target is not RT_SCREEN?
6305
6306 ref = sdci[DRAWCMD_BMP_TARGET];
6307
6308
6309 if ( ref <= 0 )
6310 {
6311 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6312 return;
6313 }
6314 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6315
6316 if(!sourceBitmap)
6317 {
6318 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6319 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6320 return;
6321 }
6322
6323 BITMAP *destBMP=NULL;
6324 switch(bitmapIndex)
6325 {
6326 case -2:
6327 {
6328 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6329 if ( curr_rt >= 0 && curr_rt < 7 )
6330 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6331 else destBMP = bmp; //screen
6332 break;
6333 }
6334 case -1:
6335 destBMP = bmp; //this is framebuf, by default
6336 break;
6337
6338 //1 through 6 are the old system bitmaps (Render Targets)
6339 case 0:
6340 case 1:
6341 case 2:
6342 case 3:
6343 case 4:
6344 case 5:
6345 case 6:
6346 {
6347 //This gets a render target.
6348 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6349 break;
6350 }
6351 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6352 default:
6353 {
6354 auto& usr_bitmap = scb.get(usr_bitmap_index);
6355 destBMP = usr_bitmap.u_bmp;
6356 if ( !usr_bitmap.u_bmp )
6357 {
6358 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6359 break;
6360 }
6361 }
6362 }
6363
6364 if (!destBMP)
6365 {
6366 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6367 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6368 return;
6369 }
6370
6371 //dx = dx + xoffset; //don't do this here!
6372 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6373 //All of these are a factor of 10000 as fix.
6374 int32_t screen_x = 0; int32_t screen_y = 0;
6375
6376 double distance = 0; double horizontal_scale = 0;
6377
6378 int32_t screen_y_horizon = 0;
6379
6380 double line_dx = 0; double line_dy = 0;
6381
6382 int32_t space_x = 0; int32_t space_y = 0;
6383
6384 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6385 {
6386 //Calculate the distance of each line from the camera point
6387 screen_y_horizon = screen_y + horizon;
6388
6389 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6390
6391 //Get the scale of each line based on the distance
6392
6393 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6394
6395 //There was some math here before I stripped out the rotation step
6396 line_dx = horizontal_scale;
6397 line_dy = 0;
6398
6399 //space_x,space_y - where to grab each scanline from on the space bitmap
6400 space_x = srcX - destW/2.0 * line_dx;
6401 space_y = srcY - distance + destH/2.0 * line_dy;
6402
6403 //Keep blits within the bounds of both bitmaps to avoid crashes
6404 int32_t y1 = srcY+space_y;
6405 int32_t y2 = destY+screen_y;
6406 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6407 {
6408 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6409 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6410 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6411 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6412 }
6413 }
6414 }
6415
6416
6417 //Draw]()
6418 264439 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6419 {
6420 /*
6421 //sdci[1]=layer
6422 //sdci[2]=bitmap target
6423 //
6424 // -2 is the current Render Target
6425 // -1, this is the screen (framebuf).
6426 // 0: Render target 0
6427 // 1: Render target 1
6428 // 2: Render target 2
6429 // 3: Render target 3
6430 // 4: Render target 4
6431 // 5: Render target 5
6432 // 6: Render target 6
6433 // Otherwise: The pointer to a bitmap.
6434
6435 //sdci[3]=sourcex
6436 //sdci[4]=sourcey
6437 //sdci[5]=sourcew
6438 //sdci[6]=sourceh
6439 //sdci[7]=destx
6440 //sdci[8]=desty
6441 //sdci[9]=destw
6442 //sdci[10]=desth
6443 //sdci[11]=rotation/angle
6444 //scdi[12] = pivot cx
6445 //sdci[13] = pivot cy
6446 //scdi[14] = effect flags
6447 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6448
6449 // ZScript-side constant values:
6450 const int32_t BITDX_NORMAL = 0;
6451 const int32_t BITDX_TRANS = 1; //Translucent
6452 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6453 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6454 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6455 //Note: Some modes cannot be combined. if a combination is not supported, an error
6456 // detailing this will be shown in allegro.log.
6457
6458 //scdi[15] = litcolour
6459 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6460 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6461
6462 //sdci[16]=mask
6463
6464 */
6465
6466 264439 int32_t bitmapIndex = sdci[2]/10000;
6467 264439 int32_t usr_bitmap_index = sdci[2];
6468
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if ( bitmapIndex > 10000 )
6469 {
6470 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6471 }
6472
3/4
✓ Branch 0 taken 172223 times.
✓ Branch 1 taken 92216 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172223 times.
264439 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
6473 {
6474 172223 bitmapIndex = usr_bitmap_index;
6475 172223 yoffset = 0;
6476 172223 }
6477
6478 264439 int32_t sx = sdci[3]/10000;
6479 264439 int32_t sy = sdci[4]/10000;
6480 264439 int32_t sw = sdci[5]/10000;
6481 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6482 264439 int32_t sh = sdci[6]/10000;
6483 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6484 264439 int32_t dx = sdci[7]/10000;
6485 264439 int32_t dy = sdci[8]/10000;
6486 264439 int32_t dw = sdci[9]/10000;
6487 264439 int32_t dh = sdci[10]/10000;
6488 264439 float rot = sdci[11]/10000;
6489 264439 int32_t cx = sdci[12]/10000;
6490 264439 int32_t cy = sdci[13]/10000;
6491 264439 int32_t mode = sdci[14]/10000;
6492 264439 int32_t litcolour = sdci[15]/10000;
6493 264439 bool masked = (sdci[16] != 0);
6494
6495 264439 int32_t ref = 0;
6496
6497 264439 dx = dx + xoffset;
6498 264439 dy = dy + yoffset;
6499
6500
2/4
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264439 times.
264439 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6501 //Do we need to also check the render target and do the same thing if the
6502 //dest == -2 and the render target is not RT_SCREEN?
6503
6504 264439 ref = sdci[DRAWCMD_BMP_TARGET];
6505
6506
6507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264439 times.
264439 if ( ref <= 0 )
6508 {
6509 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6510 return;
6511 }
6512 264439 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6513
6514
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if(!sourceBitmap)
6515 {
6516
6517 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6518 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6519 return;
6520 }
6521
6522 264439 BITMAP *destBMP=NULL;
6523
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172223 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 91430 times.
264439 switch(bitmapIndex)
6524 {
6525 case -2:
6526 {
6527 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6528
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6529 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6530 786 else destBMP = bmp; //screen
6531 786 break;
6532 }
6533 case -1:
6534 91430 destBMP = bmp; //this is framebuf, by default
6535 91430 break;
6536 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6537 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6538 //destBMP = framebuf; //Drawing to the screen.
6539 //break;
6540
6541 //1 through 6 are the old system bitmaps (Render Targets)
6542 case 0:
6543 case 1:
6544 case 2:
6545 case 3:
6546 case 4:
6547 case 5:
6548 case 6:
6549 {
6550 //This gets a render target.
6551 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6552
6553 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6554 //sdci[18] = bitmapIndex;
6555 break;
6556 }
6557 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6558 default:
6559 {
6560 172223 auto& usr_bitmap = scb.get(usr_bitmap_index);
6561 172223 destBMP = usr_bitmap.u_bmp;
6562 //sdci[18] = usr_bitmap_index;
6563
1/2
✓ Branch 0 taken 172223 times.
✗ Branch 1 not taken.
172223 if ( !usr_bitmap.u_bmp )
6564 {
6565 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6566 break;
6567 }
6568 }
6569 172223 }
6570
6571
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if (!destBMP)
6572 {
6573 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6574 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6575 return;
6576 }
6577
6578
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 263412 times.
264439 bool stretched = (sw != dw || sh != dh);
6579 264439 BITMAP* subBmp = 0;
6580
6581
4/4
✓ Branch 0 taken 262860 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 237877 times.
264439 if(rot != 0 || mode != 0)
6582 {
6583 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6584 26562 clear_bitmap(subBmp);
6585
6586
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6587 {
6588
6589 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6590 return;
6591 }
6592 26562 }
6593 264439 BITMAP* sbmp = sourceBitmap;
6594
2/4
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264439 times.
264439 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6595 {
6596 sbmp = create_bitmap_ex(8, sw, sh);
6597 clear_bitmap(sbmp);
6598 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6599 sx = 0;
6600 sy = 0;
6601 }
6602 //dx = dx + xoffset; //don't do this here!
6603 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6604
6605
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 262837 times.
264439 if(stretched)
6606 {
6607
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6608 { //stretched and masked
6609
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6610 { //if not rotated
6611
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6612 {
6613 case 1:
6614 //transparent
6615 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6616 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6617 900 break;
6618
6619
6620 case 2:
6621 //pivot?
6622 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6623 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6624 //Pivoting requires two more args
6625 break;
6626
6627 case 3:
6628 //pivot + trans
6629 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6630 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6631 break;
6632
6633 case 4:
6634 //flip v
6635 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6636 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6637 break;
6638
6639 case 5:
6640 //trans + v flip
6641 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6642 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6643 break;
6644
6645 case 6:
6646 //pivot + v flip
6647 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6648 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6649 break;
6650
6651 case 8:
6652 //vlip h
6653 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6654 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6655 break;
6656
6657 case 9:
6658 //trans + h flip
6659 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6660 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6661 break;
6662
6663 case 10:
6664 //flip H and pivot
6665 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6666 //return error cannot pivot and h flip
6667 break;
6668
6669 case 12:
6670 //vh flip
6671 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6672 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6673 break;
6674
6675 case 13:
6676 //trans + vh flip
6677 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6678 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6679 break;
6680
6681 case 14:
6682 //pivot and vh flip
6683 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6684 //return error cannot both pivot and vh flip
6685 break;
6686
6687 case 16:
6688 //lit
6689 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6690 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6691 break;
6692
6693 case 18:
6694 //pivot, lit
6695 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6696 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6697 break;
6698
6699 case 20:
6700 //lit + v flip
6701 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6702 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6703 break;
6704
6705 case 22:
6706 //Pivot, vflip, lit
6707 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6708 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6709 break;
6710
6711 case 24:
6712 //lit + h flip
6713 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6714 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6715 break;
6716
6717 case 26:
6718 //pivot + lit + hflip
6719 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6720 //return error cannot pivot, lit, and flip
6721 break;
6722
6723 case 28:
6724 //lit + vh flip
6725 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6726 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6727 break;
6728
6729 case 32: //gouraud
6730 //Probably not wort supporting.
6731 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6732 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6733 break;
6734
6735 case 0:
6736 //no effect
6737 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6738 1 break;
6739
6740
6741 default:
6742
6743 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6744
6745
6746 }
6747 901 } //end if not rotated
6748
6749
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6750 {
6751
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6752 {
6753 case 1:
6754 //transparent
6755 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6756 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6757
6758 break;
6759
6760 case 2:
6761 //pivot?
6762 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6763 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6764 //Pivoting requires two more args
6765 break;
6766
6767 case 3:
6768 //pivot + trans
6769 //return an error, cannot both rotate and pivot
6770 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6771 break;
6772
6773 case 4:
6774 //flip v
6775 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6776 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6777 break;
6778
6779 case 5:
6780 //trans + v flip
6781 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6782 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6783 break;
6784
6785 case 6:
6786 //pivot + v flip
6787 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6788 //return an error, cannot both rotate and pivot
6789 break;
6790
6791 case 8:
6792 //flip h
6793 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6794 //return an error, cannot both rotate and flip H
6795 break;
6796
6797 case 9:
6798 //trans + h flip
6799 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6800 //return an error, cannot rotate and flip a trans sprite
6801 break;
6802
6803 case 10:
6804 //flip H and pivot
6805 //return error cannot pivot and h flip
6806 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6807 break;
6808
6809 case 12:
6810 //vh flip
6811 //return an error, cannot rotate and VH flip a trans sprite
6812 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6813 break;
6814
6815 case 13:
6816 //trans + vh flip
6817 //return an error, cannot rotate and VH flip a trans sprite
6818 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6819 break;
6820
6821 case 14:
6822 //pivot and vh flip
6823 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6824 //return error cannot both pivot and vh flip
6825 break;
6826
6827 case 16:
6828 //lit
6829 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6830 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6831 break;
6832
6833 case 18:
6834 //pivot, lit
6835 //return an error, cannot both rotate and pivot
6836 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6837 break;
6838
6839 case 20:
6840 //lit + vflip
6841 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6842 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6843 break;
6844
6845 case 22:
6846 //Pivot, vflip, lit
6847 //return an error, cannot both rotate and pivot
6848 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6849 break;
6850
6851 case 24:
6852 //lit + h flip
6853 //return an error, cannot both rotate and H flip
6854 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6855 break;
6856
6857 case 26:
6858 //pivot + lit + hflip
6859 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6860 //return error cannot pivot, lit, and flip
6861 break;
6862
6863 case 28:
6864 //lit + vh flip
6865 //return an error, cannot both rotate and VH flip
6866 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6867 break;
6868
6869 case 32: //gouraud
6870 //Probably not wort supporting.
6871 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6872 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6873 break;
6874
6875 case 0:
6876 //no effect.
6877 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6878 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6879 574 break;
6880
6881 default:
6882
6883 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6884
6885 }
6886 574 }
6887 1475 } //end if stretched and masked
6888
6889 else //stretched, not masked
6890 {
6891
6892
6893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6894 {
6895
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6896 {
6897 case 1:
6898 //transparent
6899 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6901 break;
6902
6903
6904 case 2:
6905 //pivot?
6906 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6907 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6908 //Pivoting requires two more args
6909 break;
6910
6911 case 3:
6912 //pivot + trans
6913 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6914 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6915 break;
6916
6917 case 4:
6918 //flip v
6919 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6920 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6921 break;
6922
6923 case 5:
6924 //trans + v flip
6925 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6926 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6927 break;
6928
6929 case 6:
6930 //pivot + v flip
6931 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6932 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6933 break;
6934
6935 case 8:
6936 //vlip h
6937 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6938 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6939 break;
6940
6941 case 9:
6942 //trans + h flip
6943 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6944 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6945 break;
6946
6947 case 10:
6948 //flip H and pivot
6949 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6950 //return error cannot pivot and h flip
6951 break;
6952
6953 case 12:
6954 //vh flip
6955 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6956 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6957 break;
6958
6959 case 13:
6960 //trans + vh flip
6961 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6962 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6963 break;
6964
6965 case 14:
6966 //pivot and vh flip
6967 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6968 //return error cannot both pivot and vh flip
6969 break;
6970
6971 case 16:
6972 //lit
6973 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6974 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6975 break;
6976
6977 case 18:
6978 //pivot, lit
6979 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6980 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6981 break;
6982
6983 case 20:
6984 //lit + v flip
6985 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6986 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6987 break;
6988
6989 case 22:
6990 //Pivot, vflip, lit
6991 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6992 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6993 break;
6994
6995 case 24:
6996 //lit + h flip
6997 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6998 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6999 break;
7000
7001 case 26:
7002 //pivot + lit + hflip
7003 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7004 //return error cannot pivot, lit, and flip
7005 break;
7006
7007 case 28:
7008 //lit + vh flip
7009 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7010 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7011 break;
7012
7013 case 32: //gouraud
7014 //Probably not wort supporting.
7015 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7016 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7017 break;
7018
7019 case 0:
7020 //no effect
7021 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7022 127 break;
7023
7024
7025 default:
7026
7027 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7028
7029
7030 }
7031 127 } //end if not rotated
7032
7033
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7034 {
7035 switch(mode)
7036 {
7037 case 1:
7038 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7039 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7040
7041 break;
7042
7043 case 2:
7044 //pivot?
7045 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7046 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7047 //Pivoting requires two more args
7048 break;
7049
7050 case 3:
7051 //pivot + trans
7052 //return an error, cannot both rotate and pivot
7053 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7054 break;
7055
7056 case 4:
7057 //flip v
7058 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7059 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7060 break;
7061
7062 case 5:
7063 //trans + v flip
7064 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7065 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7066 break;
7067
7068 case 6:
7069 //pivot + v flip
7070 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7071 //return an error, cannot both rotate and pivot
7072 break;
7073
7074 case 8:
7075 //flip h
7076 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7077 //return an error, cannot both rotate and flip H
7078 break;
7079
7080 case 9:
7081 //trans + h flip
7082 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7083 //return an error, cannot rotate and flip a trans sprite
7084 break;
7085
7086 case 10:
7087 //flip H and pivot
7088 //return error cannot pivot and h flip
7089 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7090 break;
7091
7092 case 12:
7093 //vh flip
7094 //return an error, cannot rotate and VH flip a trans sprite
7095 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7096 break;
7097
7098 case 13:
7099 //trans + vh flip
7100 //return an error, cannot rotate and VH flip a trans sprite
7101 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7102 break;
7103
7104 case 14:
7105 //pivot and vh flip
7106 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7107 //return error cannot both pivot and vh flip
7108 break;
7109
7110 case 16:
7111 //lit
7112 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7113 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7114 break;
7115
7116 case 18:
7117 //pivot, lit
7118 //return an error, cannot both rotate and pivot
7119 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7120 break;
7121
7122 case 20:
7123 //lit + vflip
7124 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7125 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7126 break;
7127
7128 case 22:
7129 //Pivot, vflip, lit
7130 //return an error, cannot both rotate and pivot
7131 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7132 break;
7133
7134 case 24:
7135 //lit + h flip
7136 //return an error, cannot both rotate and H flip
7137 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7138 break;
7139
7140 case 26:
7141 //pivot + lit + hflip
7142 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7143 //return error cannot pivot, lit, and flip
7144 break;
7145
7146 case 28:
7147 //lit + vh flip
7148 //return an error, cannot both rotate and VH flip
7149 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7150 break;
7151
7152 case 32: //gouraud
7153 //Probably not wort supporting.
7154 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7155 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7156 break;
7157
7158 case 0:
7159 //no effect.
7160 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7161 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7162 break;
7163
7164 default:
7165
7166 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7167
7168 }
7169 }
7170
7171 } //end if stretched, but not masked
7172 1602 }
7173 else //not stretched
7174 {
7175
7176
2/2
✓ Branch 0 taken 251854 times.
✓ Branch 1 taken 10983 times.
262837 if(masked) //if masked, but not stretched
7177 {
7178
7179
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 250849 times.
251854 if ( rot == 0 ) //if not rotated
7180 {
7181
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 232160 times.
250849 switch(mode)
7182 {
7183 case 1:
7184 //transparent
7185 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7186 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7187 18689 break;
7188
7189
7190 case 2:
7191 //pivot?
7192 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7193 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7194 //Pivoting requires two more args
7195 break;
7196
7197 case 3:
7198 //pivot + trans
7199 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7200 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7201 break;
7202
7203 case 4:
7204 //flip v
7205 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7206 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7207 break;
7208
7209 case 5:
7210 //trans + v flip
7211 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7212 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7213 break;
7214
7215 case 6:
7216 //pivot + v flip
7217 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7218 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7219 break;
7220
7221 case 8:
7222 //vlip h
7223 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7224 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7225 break;
7226
7227 case 9:
7228 //trans + h flip
7229 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7230 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7231 break;
7232
7233 case 10:
7234 //flip H and pivot
7235 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7236 //return error cannot pivot and h flip
7237 break;
7238
7239 case 12:
7240 //vh flip
7241 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7242 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7243 break;
7244
7245 case 13:
7246 //trans + vh flip
7247 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7248 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7249 break;
7250
7251 case 14:
7252 //pivot and vh flip
7253 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7254 //return error cannot both pivot and vh flip
7255 break;
7256
7257 case 16:
7258 //lit
7259 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7260 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7261 break;
7262
7263 case 18:
7264 //pivot, lit
7265 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7266 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7267 break;
7268
7269 case 20:
7270 //lit + v flip
7271 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7272 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7273 break;
7274
7275 case 22:
7276 //Pivot, vflip, lit
7277 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7278 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7279 break;
7280
7281 case 24:
7282 //lit + h flip
7283 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7284 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7285 break;
7286
7287 case 26:
7288 //pivot + lit + hflip
7289 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7290 //return error cannot pivot, lit, and flip
7291 break;
7292
7293 case 28:
7294 //lit + vh flip
7295 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7296 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7297 break;
7298
7299 case 32: //gouraud
7300 //Probably not wort supporting.
7301 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7302 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7303 break;
7304
7305 case 0:
7306 //no effect
7307 232160 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7308 232160 break;
7309
7310
7311 default:
7312
7313 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7314
7315
7316 }
7317 250849 } //end if not rotated
7318
7319
2/2
✓ Branch 0 taken 250849 times.
✓ Branch 1 taken 1005 times.
251854 if ( rot != 0 ) //if rotated
7320 {
7321
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7322 {
7323 case 1:
7324 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7325 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7326
7327 break;
7328
7329 case 2:
7330 //pivot?
7331 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7332 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7333 //Pivoting requires two more args
7334 break;
7335
7336 case 3:
7337 //pivot + trans
7338 //return an error, cannot both rotate and pivot
7339 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7340 break;
7341
7342 case 4:
7343 //flip v
7344 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7345 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7346 break;
7347
7348 case 5:
7349 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7350 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7351 break;
7352
7353 case 6:
7354 //pivot + v flip
7355 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7356 //return an error, cannot both rotate and pivot
7357 break;
7358
7359 case 8:
7360 //flip h
7361 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7362 //return an error, cannot both rotate and flip H
7363 break;
7364
7365 case 9:
7366 //trans + h flip
7367 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7368 //return an error, cannot rotate and flip a trans sprite
7369 break;
7370
7371 case 10:
7372 //flip H and pivot
7373 //return error cannot pivot and h flip
7374 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7375 break;
7376
7377 case 12:
7378 //vh flip
7379 //return an error, cannot rotate and VH flip a trans sprite
7380 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7381 break;
7382
7383 case 13:
7384 //trans + vh flip
7385 //return an error, cannot rotate and VH flip a trans sprite
7386 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7387 break;
7388
7389 case 14:
7390 //pivot and vh flip
7391 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7392 //return error cannot both pivot and vh flip
7393 break;
7394
7395 case 16:
7396 //lit
7397 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7398 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7399 break;
7400
7401 case 18:
7402 //pivot, lit
7403 //return an error, cannot both rotate and pivot
7404 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7405 break;
7406
7407 case 20:
7408 //lit + vflip
7409 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7410 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7411 break;
7412
7413 case 22:
7414 //Pivot, vflip, lit
7415 //return an error, cannot both rotate and pivot
7416 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7417 break;
7418
7419 case 24:
7420 //lit + h flip
7421 //return an error, cannot both rotate and H flip
7422 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7423 break;
7424
7425 case 26:
7426 //pivot + lit + hflip
7427 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7428 //return error cannot pivot, lit, and flip
7429 break;
7430
7431 case 28:
7432 //lit + vh flip
7433 //return an error, cannot both rotate and VH flip
7434 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7435 break;
7436
7437 case 32: //gouraud
7438 //Probably not wort supporting.
7439 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7440 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7441 break;
7442
7443 case 0:
7444 //no effect.
7445 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7446 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7447 1005 break;
7448
7449 default:
7450
7451 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7452
7453 }
7454 1005 } //end rtated, masked
7455 251854 } //end if masked
7456
7457 else //not masked, and not stretched; just blit
7458 {
7459
7460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7461 {
7462
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7463 {
7464 case 1:
7465 //transparent
7466 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7467 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7468 5394 break;
7469
7470
7471 case 2:
7472 //pivot?
7473 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7474 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7475 //Pivoting requires two more args
7476 break;
7477
7478 case 3:
7479 //pivot + trans
7480 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7481 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7482 break;
7483
7484 case 4:
7485 //flip v
7486 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7487 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7488 break;
7489
7490 case 5:
7491 //trans + v flip
7492 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7493 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7494 break;
7495
7496 case 6:
7497 //pivot + v flip
7498 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7499 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7500 break;
7501
7502 case 8:
7503 //vlip h
7504 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7505 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7506 break;
7507
7508 case 9:
7509 //trans + h flip
7510 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7511 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7512 break;
7513
7514 case 10:
7515 //flip H and pivot
7516 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7517 //return error cannot pivot and h flip
7518 break;
7519
7520 case 12:
7521 //vh flip
7522 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7523 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7524 break;
7525
7526 case 13:
7527 //trans + vh flip
7528 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7529 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7530 break;
7531
7532 case 14:
7533 //pivot and vh flip
7534 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7535 //return error cannot both pivot and vh flip
7536 break;
7537
7538 case 16:
7539 //lit
7540 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7541 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7542 break;
7543
7544 case 18:
7545 //pivot, lit
7546 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7547 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7548 break;
7549
7550 case 20:
7551 //lit + v flip
7552 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7553 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7554 break;
7555
7556 case 22:
7557 //Pivot, vflip, lit
7558 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7559 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7560 break;
7561
7562 case 24:
7563 //lit + h flip
7564 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7565 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7566 break;
7567
7568 case 26:
7569 //pivot + lit + hflip
7570 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7571 //return error cannot pivot, lit, and flip
7572 break;
7573
7574 case 28:
7575 //lit + vh flip
7576 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7577 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7578 break;
7579
7580 case 32: //gouraud
7581 //Probably not wort supporting.
7582 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7583 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7584 break;
7585
7586 case 0:
7587 //no effect
7588 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7589 5589 break;
7590
7591
7592 default:
7593
7594 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7595
7596
7597 }
7598 10983 } //end if not rotated
7599
7600
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7601 {
7602 switch(mode)
7603 {
7604 case 1:
7605 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7606 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7607
7608 break;
7609
7610 case 2:
7611 //pivot?
7612 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7613 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7614 //Pivoting requires two more args
7615 break;
7616
7617 case 3:
7618 //pivot + trans
7619 //return an error, cannot both rotate and pivot
7620 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7621 break;
7622
7623 case 4:
7624 //flip v
7625 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7626 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7627 break;
7628
7629 case 5:
7630 //trans + v flip
7631 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7632 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7633 break;
7634
7635 case 6:
7636 //pivot + v flip
7637 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7638 //return an error, cannot both rotate and pivot
7639 break;
7640
7641 case 8:
7642 //flip h
7643 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7644 //return an error, cannot both rotate and flip H
7645 break;
7646
7647 case 9:
7648 //trans + h flip
7649 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7650 //return an error, cannot rotate and flip a trans sprite
7651 break;
7652
7653 case 10:
7654 //flip H and pivot
7655 //return error cannot pivot and h flip
7656 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7657 break;
7658
7659 case 12:
7660 //vh flip
7661 //return an error, cannot rotate and VH flip a trans sprite
7662 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7663 break;
7664
7665 case 13:
7666 //trans + vh flip
7667 //return an error, cannot rotate and VH flip a trans sprite
7668 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7669 break;
7670
7671 case 14:
7672 //pivot and vh flip
7673 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7674 //return error cannot both pivot and vh flip
7675 break;
7676
7677 case 16:
7678 //lit
7679 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7680 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7681 break;
7682
7683 case 18:
7684 //pivot, lit
7685 //return an error, cannot both rotate and pivot
7686 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7687 break;
7688
7689 case 20:
7690 //lit + vflip
7691 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7692 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7693 break;
7694
7695 case 22:
7696 //Pivot, vflip, lit
7697 //return an error, cannot both rotate and pivot
7698 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7699 break;
7700
7701 case 24:
7702 //lit + h flip
7703 //return an error, cannot both rotate and H flip
7704 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7705 break;
7706
7707 case 26:
7708 //pivot + lit + hflip
7709 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7710 //return error cannot pivot, lit, and flip
7711 break;
7712
7713 case 28:
7714 //lit + vh flip
7715 //return an error, cannot both rotate and VH flip
7716 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7717 break;
7718
7719 case 32: //gouraud
7720 //Probably not wort supporting.
7721 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7722 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7723 break;
7724
7725 case 0:
7726 //no effect.
7727 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7728 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7729 break;
7730
7731 default:
7732
7733 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7734
7735 }
7736 } //end if rotated
7737 } //end if not masked
7738 } //end if not stretched
7739
7740 //cleanup
7741
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 237877 times.
264439 if(subBmp)
7742 {
7743 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7744 26562 destroy_bitmap(subBmp);
7745 26562 }
7746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264439 times.
264439 if (sbmp != sourceBitmap)
7747 {
7748 destroy_bitmap(sbmp);
7749 }
7750 264439 }
7751
7752
7753
7754 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7755 {
7756 /*
7757 //sdci[1]=layer
7758 //sdci[2]=bitmap target
7759 //
7760 // -2 is the current Render Target
7761 // -1, this is the screen (framebuf).
7762 // 0: Render target 0
7763 // 1: Render target 1
7764 // 2: Render target 2
7765 // 3: Render target 3
7766 // 4: Render target 4
7767 // 5: Render target 5
7768 // 6: Render target 6
7769 // Otherwise: The pointer to a bitmap.
7770
7771 //sdci[3]=sourcex
7772 //sdci[4]=sourcey
7773 //sdci[5]=sourcew
7774 //sdci[6]=sourceh
7775 //sdci[7]=destx
7776 //sdci[8]=desty
7777 //sdci[9]=destw
7778 //sdci[10]=desth
7779 //sdci[11]=rotation/angle
7780 //scdi[12] = pivot cx
7781 //sdci[13] = pivot cy
7782 //scdi[14] = effect flags
7783 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
7784
7785 // ZScript-side constant values:
7786 const int32_t BITDX_NORMAL = 0;
7787 const int32_t BITDX_TRANS = 1; //Translucent
7788 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7789 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7790 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7791 //Note: Some modes cannot be combined. if a combination is not supported, an error
7792 // detailing this will be shown in allegro.log.
7793
7794 //scdi[15] = litcolour
7795 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7796 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7797
7798 //sdci[16]=mask
7799
7800 */
7801
7802 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7803 113329 int32_t bitmapIndex = sdci[2]/10000;
7804 113329 int32_t usr_bitmap_index = sdci[2];
7805
7806
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if ( bitmapIndex > 10000 )
7807 {
7808 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
7809 }
7810
3/4
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 113326 times.
113329 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
7811 {
7812 113326 bitmapIndex = usr_bitmap_index;
7813 113326 srcyoffset = 0;
7814 113326 }
7815
7816 113329 int32_t sx = sdci[3]/10000;
7817 113329 int32_t sy = sdci[4]/10000;
7818 113329 int32_t sw = sdci[5]/10000;
7819 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
7820 113329 int32_t sh = sdci[6]/10000;
7821 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
7822 113329 int32_t dx = sdci[7]/10000;
7823 113329 int32_t dy = sdci[8]/10000;
7824 113329 int32_t dw = sdci[9]/10000;
7825 113329 int32_t dh = sdci[10]/10000;
7826 113329 float rot = sdci[11]/10000;
7827 113329 int32_t cx = sdci[12]/10000;
7828 113329 int32_t cy = sdci[13]/10000;
7829 113329 int32_t mode = sdci[14]/10000;
7830 113329 int32_t litcolour = sdci[15]/10000;
7831 113329 bool masked = (sdci[16] != 0);
7832
7833 113329 int32_t ref = 0;
7834
7835 //These should go down farther, should they not? -V
7836 //dx = dx + xoffset;
7837 //dy = dy + yoffset;
7838
7839
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
7840
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7841 //Do we need to also check the render target and do the same thing if the
7842 //dest == -2 and the render target is not RT_SCREEN?
7843 113329 dx = dx + xoffset;
7844 113329 dy = dy + yoffset;
7845 113329 sx = sx + srcxoffset;
7846 113329 sy = sy + srcyoffset;
7847
7848 113329 ref = sdci[DRAWCMD_BMP_TARGET];
7849
7850
7851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7852 {
7853 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7854 return;
7855 }
7856 113329 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
7857
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7858 {
7859 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7860 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7861 return;
7862 }
7863
7864 113329 BITMAP *destBMP=NULL;
7865
7866
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7867 {
7868 case -2:
7869 {
7870 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7871 if ( curr_rt >= 0 && curr_rt < 7 )
7872 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7873 else destBMP = bmp; //screen
7874 break;
7875 }
7876 case -1:
7877 3 destBMP = bmp; //this is framebuf, by default
7878 3 break;
7879 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7880 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7881 //destBMP = framebuf; //Drawing to the screen.
7882 //break;
7883
7884 //1 through 6 are the old system bitmaps (Render Targets)
7885 case 0:
7886 case 1:
7887 case 2:
7888 case 3:
7889 case 4:
7890 case 5:
7891 case 6:
7892 {
7893 //This gets a render target.
7894 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7895
7896 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7897 //sdci[18] = bitmapIndex;
7898 break;
7899 }
7900 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7901 default:
7902 {
7903 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7904 113326 destBMP = usr_bitmap.u_bmp;
7905 //sdci[18] = usr_bitmap_index;
7906
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7907 {
7908 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7909 break;
7910 }
7911 }
7912 113326 }
7913
7914
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7915 {
7916 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7917 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7918 return;
7919 }
7920
7921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
7922
7923 113329 BITMAP* newDest = sourceBitmap;
7924 113329 BITMAP* newSource = destBMP; //Flip them.
7925
7926 113329 BITMAP* subBmp = 0;
7927
7928
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
7929 {
7930 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
7931 clear_bitmap(subBmp);
7932
7933 if(!subBmp)
7934 {
7935 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
7936 return;
7937 }
7938 }
7939
7940
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
7941 {
7942 3 newSource = create_bitmap_ex(8, sw, sh);
7943 3 clear_bitmap(newSource);
7944 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
7945 3 sx = 0;
7946 3 sy = 0;
7947 3 }
7948 //dx = dx + xoffset; //don't do this here!
7949 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
7950
7951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
7952 {
7953 if(masked)
7954 { //stretched and masked
7955 if ( rot == 0 )
7956 { //if not rotated
7957 switch(mode)
7958 {
7959 case 1:
7960 //transparent
7961 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7962 draw_trans_sprite(newDest, subBmp, dx, dy);
7963 break;
7964
7965
7966 case 2:
7967 //pivot?
7968 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7969 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7970 //Pivoting requires two more args
7971 break;
7972
7973 case 3:
7974 //pivot + trans
7975 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7976 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7977 break;
7978
7979 case 4:
7980 //flip v
7981 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7982 draw_sprite_v_flip(newDest, subBmp, dx, dy);
7983 break;
7984
7985 case 5:
7986 //trans + v flip
7987 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7988 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7989 break;
7990
7991 case 6:
7992 //pivot + v flip
7993 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7994 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7995 break;
7996
7997 case 8:
7998 //vlip h
7999 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8000 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8001 break;
8002
8003 case 9:
8004 //trans + h flip
8005 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8006 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8007 break;
8008
8009 case 10:
8010 //flip H and pivot
8011 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8012 //return error cannot pivot and h flip
8013 break;
8014
8015 case 12:
8016 //vh flip
8017 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8018 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8019 break;
8020
8021 case 13:
8022 //trans + vh flip
8023 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8024 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8025 break;
8026
8027 case 14:
8028 //pivot and vh flip
8029 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8030 //return error cannot both pivot and vh flip
8031 break;
8032
8033 case 16:
8034 //lit
8035 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8036 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8037 break;
8038
8039 case 18:
8040 //pivot, lit
8041 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8042 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8043 break;
8044
8045 case 20:
8046 //lit + v flip
8047 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8048 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8049 break;
8050
8051 case 22:
8052 //Pivot, vflip, lit
8053 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8054 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8055 break;
8056
8057 case 24:
8058 //lit + h flip
8059 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8060 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8061 break;
8062
8063 case 26:
8064 //pivot + lit + hflip
8065 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8066 //return error cannot pivot, lit, and flip
8067 break;
8068
8069 case 28:
8070 //lit + vh flip
8071 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8072 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8073 break;
8074
8075 case 32: //gouraud
8076 //Probably not wort supporting.
8077 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8078 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8079 break;
8080
8081 case 0:
8082 //no effect
8083 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8084 break;
8085
8086
8087 default:
8088 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8089
8090
8091 }
8092 } //end if not rotated
8093
8094 if ( rot != 0 ) //if rotated
8095 {
8096 switch(mode)
8097 {
8098 case 1:
8099 //transparent
8100 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8101 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8102
8103 break;
8104
8105 case 2:
8106 //pivot?
8107 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8108 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8109 //Pivoting requires two more args
8110 break;
8111
8112 case 3:
8113 //pivot + trans
8114 //return an error, cannot both rotate and pivot
8115 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8116 break;
8117
8118 case 4:
8119 //flip v
8120 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8121 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8122 break;
8123
8124 case 5:
8125 //trans + v flip
8126 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8127 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8128 break;
8129
8130 case 6:
8131 //pivot + v flip
8132 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8133 //return an error, cannot both rotate and pivot
8134 break;
8135
8136 case 8:
8137 //flip h
8138 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8139 //return an error, cannot both rotate and flip H
8140 break;
8141
8142 case 9:
8143 //trans + h flip
8144 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8145 //return an error, cannot rotate and flip a trans sprite
8146 break;
8147
8148 case 10:
8149 //flip H and pivot
8150 //return error cannot pivot and h flip
8151 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8152 break;
8153
8154 case 12:
8155 //vh flip
8156 //return an error, cannot rotate and VH flip a trans sprite
8157 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8158 break;
8159
8160 case 13:
8161 //trans + vh flip
8162 //return an error, cannot rotate and VH flip a trans sprite
8163 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8164 break;
8165
8166 case 14:
8167 //pivot and vh flip
8168 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8169 //return error cannot both pivot and vh flip
8170 break;
8171
8172 case 16:
8173 //lit
8174 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8175 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8176 break;
8177
8178 case 18:
8179 //pivot, lit
8180 //return an error, cannot both rotate and pivot
8181 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8182 break;
8183
8184 case 20:
8185 //lit + vflip
8186 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8187 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8188 break;
8189
8190 case 22:
8191 //Pivot, vflip, lit
8192 //return an error, cannot both rotate and pivot
8193 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8194 break;
8195
8196 case 24:
8197 //lit + h flip
8198 //return an error, cannot both rotate and H flip
8199 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8200 break;
8201
8202 case 26:
8203 //pivot + lit + hflip
8204 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8205 //return error cannot pivot, lit, and flip
8206 break;
8207
8208 case 28:
8209 //lit + vh flip
8210 //return an error, cannot both rotate and VH flip
8211 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8212 break;
8213
8214 case 32: //gouraud
8215 //Probably not wort supporting.
8216 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8217 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8218 break;
8219
8220 case 0:
8221 //no effect.
8222 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8223 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8224 break;
8225
8226 default:
8227 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8228
8229 }
8230 }
8231 } //end if stretched and masked
8232
8233 else //stretched, not masked
8234 {
8235
8236
8237 if ( rot == 0 ) //if not rotated
8238 {
8239 switch(mode)
8240 {
8241 case 1:
8242 //transparent
8243 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8244 draw_trans_sprite(newDest, subBmp, dx, dy);
8245 break;
8246
8247
8248 case 2:
8249 //pivot?
8250 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8251 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8252 //Pivoting requires two more args
8253 break;
8254
8255 case 3:
8256 //pivot + trans
8257 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8258 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8259 break;
8260
8261 case 4:
8262 //flip v
8263 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8264 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8265 break;
8266
8267 case 5:
8268 //trans + v flip
8269 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8270 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8271 break;
8272
8273 case 6:
8274 //pivot + v flip
8275 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8276 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8277 break;
8278
8279 case 8:
8280 //vlip h
8281 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8282 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8283 break;
8284
8285 case 9:
8286 //trans + h flip
8287 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8288 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8289 break;
8290
8291 case 10:
8292 //flip H and pivot
8293 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8294 //return error cannot pivot and h flip
8295 break;
8296
8297 case 12:
8298 //vh flip
8299 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8300 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8301 break;
8302
8303 case 13:
8304 //trans + vh flip
8305 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8306 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8307 break;
8308
8309 case 14:
8310 //pivot and vh flip
8311 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8312 //return error cannot both pivot and vh flip
8313 break;
8314
8315 case 16:
8316 //lit
8317 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8318 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8319 break;
8320
8321 case 18:
8322 //pivot, lit
8323 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8324 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8325 break;
8326
8327 case 20:
8328 //lit + v flip
8329 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8330 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8331 break;
8332
8333 case 22:
8334 //Pivot, vflip, lit
8335 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8336 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8337 break;
8338
8339 case 24:
8340 //lit + h flip
8341 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8342 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8343 break;
8344
8345 case 26:
8346 //pivot + lit + hflip
8347 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8348 //return error cannot pivot, lit, and flip
8349 break;
8350
8351 case 28:
8352 //lit + vh flip
8353 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8354 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8355 break;
8356
8357 case 32: //gouraud
8358 //Probably not wort supporting.
8359 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8360 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8361 break;
8362
8363 case 0:
8364 //no effect
8365 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8366 break;
8367
8368
8369 default:
8370 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8371
8372
8373 }
8374 } //end if not rotated
8375
8376 if ( rot != 0 ) //if rotated
8377 {
8378 switch(mode)
8379 {
8380 case 1:
8381 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8382 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8383
8384 break;
8385
8386 case 2:
8387 //pivot?
8388 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8389 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8390 //Pivoting requires two more args
8391 break;
8392
8393 case 3:
8394 //pivot + trans
8395 //return an error, cannot both rotate and pivot
8396 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8397 break;
8398
8399 case 4:
8400 //flip v
8401 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8402 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8403 break;
8404
8405 case 5:
8406 //trans + v flip
8407 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8408 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8409 break;
8410
8411 case 6:
8412 //pivot + v flip
8413 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8414 //return an error, cannot both rotate and pivot
8415 break;
8416
8417 case 8:
8418 //flip h
8419 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8420 //return an error, cannot both rotate and flip H
8421 break;
8422
8423 case 9:
8424 //trans + h flip
8425 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8426 //return an error, cannot rotate and flip a trans sprite
8427 break;
8428
8429 case 10:
8430 //flip H and pivot
8431 //return error cannot pivot and h flip
8432 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8433 break;
8434
8435 case 12:
8436 //vh flip
8437 //return an error, cannot rotate and VH flip a trans sprite
8438 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8439 break;
8440
8441 case 13:
8442 //trans + vh flip
8443 //return an error, cannot rotate and VH flip a trans sprite
8444 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8445 break;
8446
8447 case 14:
8448 //pivot and vh flip
8449 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8450 //return error cannot both pivot and vh flip
8451 break;
8452
8453 case 16:
8454 //lit
8455 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8456 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8457 break;
8458
8459 case 18:
8460 //pivot, lit
8461 //return an error, cannot both rotate and pivot
8462 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8463 break;
8464
8465 case 20:
8466 //lit + vflip
8467 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8468 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8469 break;
8470
8471 case 22:
8472 //Pivot, vflip, lit
8473 //return an error, cannot both rotate and pivot
8474 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8475 break;
8476
8477 case 24:
8478 //lit + h flip
8479 //return an error, cannot both rotate and H flip
8480 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8481 break;
8482
8483 case 26:
8484 //pivot + lit + hflip
8485 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8486 //return error cannot pivot, lit, and flip
8487 break;
8488
8489 case 28:
8490 //lit + vh flip
8491 //return an error, cannot both rotate and VH flip
8492 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8493 break;
8494
8495 case 32: //gouraud
8496 //Probably not wort supporting.
8497 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8498 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8499 break;
8500
8501 case 0:
8502 //no effect.
8503 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8504 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8505 break;
8506
8507 default:
8508 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8509
8510 }
8511 }
8512
8513 } //end if stretched, but not masked
8514 }
8515 else //not stretched
8516 {
8517
8518
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8519 {
8520
8521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8522 {
8523
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8524 {
8525 case 1:
8526 //transparent
8527 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8528 draw_trans_sprite(newDest, subBmp, dx, dy);
8529 break;
8530
8531
8532 case 2:
8533 //pivot?
8534 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8535 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8536 //Pivoting requires two more args
8537 break;
8538
8539 case 3:
8540 //pivot + trans
8541 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8542 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8543 break;
8544
8545 case 4:
8546 //flip v
8547 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8548 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8549 break;
8550
8551 case 5:
8552 //trans + v flip
8553 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8554 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8555 break;
8556
8557 case 6:
8558 //pivot + v flip
8559 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8560 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8561 break;
8562
8563 case 8:
8564 //vlip h
8565 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8566 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8567 break;
8568
8569 case 9:
8570 //trans + h flip
8571 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8572 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8573 break;
8574
8575 case 10:
8576 //flip H and pivot
8577 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8578 //return error cannot pivot and h flip
8579 break;
8580
8581 case 12:
8582 //vh flip
8583 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8584 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8585 break;
8586
8587 case 13:
8588 //trans + vh flip
8589 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8590 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8591 break;
8592
8593 case 14:
8594 //pivot and vh flip
8595 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8596 //return error cannot both pivot and vh flip
8597 break;
8598
8599 case 16:
8600 //lit
8601 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8602 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8603 break;
8604
8605 case 18:
8606 //pivot, lit
8607 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8608 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8609 break;
8610
8611 case 20:
8612 //lit + v flip
8613 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8614 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8615 break;
8616
8617 case 22:
8618 //Pivot, vflip, lit
8619 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8620 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8621 break;
8622
8623 case 24:
8624 //lit + h flip
8625 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8626 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8627 break;
8628
8629 case 26:
8630 //pivot + lit + hflip
8631 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8632 //return error cannot pivot, lit, and flip
8633 break;
8634
8635 case 28:
8636 //lit + vh flip
8637 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8638 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8639 break;
8640
8641 case 32: //gouraud
8642 //Probably not wort supporting.
8643 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8644 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8645 break;
8646
8647 case 0:
8648 //no effect
8649 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8650 113326 break;
8651
8652
8653 default:
8654 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8655
8656
8657 }
8658 113326 } //end if not rotated
8659
8660
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8661 {
8662 switch(mode)
8663 {
8664 case 1:
8665 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8666 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8667
8668 break;
8669
8670 case 2:
8671 //pivot?
8672 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8673 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8674 //Pivoting requires two more args
8675 break;
8676
8677 case 3:
8678 //pivot + trans
8679 //return an error, cannot both rotate and pivot
8680 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8681 break;
8682
8683 case 4:
8684 //flip v
8685 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8686 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8687 break;
8688
8689 case 5:
8690 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8691 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8692 break;
8693
8694 case 6:
8695 //pivot + v flip
8696 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8697 //return an error, cannot both rotate and pivot
8698 break;
8699
8700 case 8:
8701 //flip h
8702 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8703 //return an error, cannot both rotate and flip H
8704 break;
8705
8706 case 9:
8707 //trans + h flip
8708 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8709 //return an error, cannot rotate and flip a trans sprite
8710 break;
8711
8712 case 10:
8713 //flip H and pivot
8714 //return error cannot pivot and h flip
8715 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8716 break;
8717
8718 case 12:
8719 //vh flip
8720 //return an error, cannot rotate and VH flip a trans sprite
8721 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8722 break;
8723
8724 case 13:
8725 //trans + vh flip
8726 //return an error, cannot rotate and VH flip a trans sprite
8727 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8728 break;
8729
8730 case 14:
8731 //pivot and vh flip
8732 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8733 //return error cannot both pivot and vh flip
8734 break;
8735
8736 case 16:
8737 //lit
8738 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8739 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8740 break;
8741
8742 case 18:
8743 //pivot, lit
8744 //return an error, cannot both rotate and pivot
8745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8746 break;
8747
8748 case 20:
8749 //lit + vflip
8750 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8751 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8752 break;
8753
8754 case 22:
8755 //Pivot, vflip, lit
8756 //return an error, cannot both rotate and pivot
8757 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8758 break;
8759
8760 case 24:
8761 //lit + h flip
8762 //return an error, cannot both rotate and H flip
8763 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8764 break;
8765
8766 case 26:
8767 //pivot + lit + hflip
8768 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8769 //return error cannot pivot, lit, and flip
8770 break;
8771
8772 case 28:
8773 //lit + vh flip
8774 //return an error, cannot both rotate and VH flip
8775 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8776 break;
8777
8778 case 32: //gouraud
8779 //Probably not wort supporting.
8780 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8781 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8782 break;
8783
8784 case 0:
8785 //no effect.
8786 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8787 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8788 break;
8789
8790 default:
8791 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8792
8793 }
8794 } //end rtated, masked
8795 113326 } //end if masked
8796
8797 else //not masked, and not stretched; just blit
8798 {
8799
8800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8801 {
8802
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8803 {
8804 case 1:
8805 //transparent
8806 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8807 draw_trans_sprite(newDest, subBmp, dx, dy);
8808 break;
8809
8810
8811 case 2:
8812 //pivot?
8813 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8814 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8815 //Pivoting requires two more args
8816 break;
8817
8818 case 3:
8819 //pivot + trans
8820 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8821 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8822 break;
8823
8824 case 4:
8825 //flip v
8826 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8827 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8828 break;
8829
8830 case 5:
8831 //trans + v flip
8832 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8833 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8834 break;
8835
8836 case 6:
8837 //pivot + v flip
8838 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8839 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8840 break;
8841
8842 case 8:
8843 //vlip h
8844 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8845 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8846 break;
8847
8848 case 9:
8849 //trans + h flip
8850 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8851 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8852 break;
8853
8854 case 10:
8855 //flip H and pivot
8856 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8857 //return error cannot pivot and h flip
8858 break;
8859
8860 case 12:
8861 //vh flip
8862 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8863 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8864 break;
8865
8866 case 13:
8867 //trans + vh flip
8868 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8869 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8870 break;
8871
8872 case 14:
8873 //pivot and vh flip
8874 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8875 //return error cannot both pivot and vh flip
8876 break;
8877
8878 case 16:
8879 //lit
8880 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8881 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8882 break;
8883
8884 case 18:
8885 //pivot, lit
8886 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8887 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8888 break;
8889
8890 case 20:
8891 //lit + v flip
8892 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8893 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8894 break;
8895
8896 case 22:
8897 //Pivot, vflip, lit
8898 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8899 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8900 break;
8901
8902 case 24:
8903 //lit + h flip
8904 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8905 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8906 break;
8907
8908 case 26:
8909 //pivot + lit + hflip
8910 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8911 //return error cannot pivot, lit, and flip
8912 break;
8913
8914 case 28:
8915 //lit + vh flip
8916 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8917 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8918 break;
8919
8920 case 32: //gouraud
8921 //Probably not wort supporting.
8922 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8923 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8924 break;
8925
8926 case 0:
8927 //no effect
8928 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8929 3 break;
8930
8931
8932 default:
8933 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8934
8935
8936 }
8937 3 } //end if not rotated
8938
8939
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
8940 {
8941 switch(mode)
8942 {
8943 case 1:
8944 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
8945 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8946
8947 break;
8948
8949 case 2:
8950 //pivot?
8951 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8952 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8953 //Pivoting requires two more args
8954 break;
8955
8956 case 3:
8957 //pivot + trans
8958 //return an error, cannot both rotate and pivot
8959 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8960 break;
8961
8962 case 4:
8963 //flip v
8964 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8965 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8966 break;
8967
8968 case 5:
8969 //trans + v flip
8970 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8971 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8972 break;
8973
8974 case 6:
8975 //pivot + v flip
8976 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8977 //return an error, cannot both rotate and pivot
8978 break;
8979
8980 case 8:
8981 //flip h
8982 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8983 //return an error, cannot both rotate and flip H
8984 break;
8985
8986 case 9:
8987 //trans + h flip
8988 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8989 //return an error, cannot rotate and flip a trans sprite
8990 break;
8991
8992 case 10:
8993 //flip H and pivot
8994 //return error cannot pivot and h flip
8995 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8996 break;
8997
8998 case 12:
8999 //vh flip
9000 //return an error, cannot rotate and VH flip a trans sprite
9001 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9002 break;
9003
9004 case 13:
9005 //trans + vh flip
9006 //return an error, cannot rotate and VH flip a trans sprite
9007 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9008 break;
9009
9010 case 14:
9011 //pivot and vh flip
9012 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9013 //return error cannot both pivot and vh flip
9014 break;
9015
9016 case 16:
9017 //lit
9018 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9019 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9020 break;
9021
9022 case 18:
9023 //pivot, lit
9024 //return an error, cannot both rotate and pivot
9025 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9026 break;
9027
9028 case 20:
9029 //lit + vflip
9030 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9031 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9032 break;
9033
9034 case 22:
9035 //Pivot, vflip, lit
9036 //return an error, cannot both rotate and pivot
9037 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9038 break;
9039
9040 case 24:
9041 //lit + h flip
9042 //return an error, cannot both rotate and H flip
9043 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9044 break;
9045
9046 case 26:
9047 //pivot + lit + hflip
9048 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9049 //return error cannot pivot, lit, and flip
9050 break;
9051
9052 case 28:
9053 //lit + vh flip
9054 //return an error, cannot both rotate and VH flip
9055 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9056 break;
9057
9058 case 32: //gouraud
9059 //Probably not wort supporting.
9060 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9061 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9062 break;
9063
9064 case 0:
9065 //no effect.
9066 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9067 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9068 break;
9069
9070 default:
9071 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9072
9073 }
9074 } //end if rotated
9075 } //end if not masked
9076 } //end if not stretched
9077
9078 //cleanup
9079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9080 {
9081 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9082 destroy_bitmap(subBmp);
9083 }
9084
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9085 {
9086 3 destroy_bitmap(newSource);
9087 3 }
9088 113329 }
9089
9090 void do_tileblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp, char const* funcstr)
9091 {
9092 /*
9093 //sdci[1]=layer
9094 //sdci[2]=tile
9095 //sdci[3]=cset
9096 //sdci[4]=sourcex
9097 //sdci[5]=sourcey
9098 //sdci[6]=sourcew
9099 //sdci[7]=sourceh
9100 //sdci[8]=destx
9101 //sdci[9]=desty
9102 //sdci[10]=destw
9103 //sdci[11]=desth
9104 //sdci[12]=rotation/angle
9105 //scdi[13] = pivot cx
9106 //sdci[14] = pivot cy
9107 //scdi[15] = effect flags
9108
9109 // ZScript-side constant values:
9110 const int32_t BITDX_NORMAL = 0;
9111 const int32_t BITDX_TRANS = 1; //Translucent
9112 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
9113 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
9114 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
9115 //Note: Some modes cannot be combined. if a combination is not supported, an error
9116 // detailing this will be shown in allegro.log.
9117
9118 //scdi[16] = litcolour
9119 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9120 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
9121
9122 //sdci[17]=mask
9123 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
9124
9125 */
9126
9127 int32_t tile = sdci[2]/10000;
9128 int32_t cset = WRAP_CS(sdci[3]/10000);
9129
9130 int32_t sx = sdci[4]/10000;
9131 int32_t sy = sdci[5]/10000;
9132 int32_t sw = sdci[6]/10000;
9133 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
9134 int32_t sh = sdci[7]/10000;
9135 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
9136 int32_t dx = sdci[8]/10000;
9137 int32_t dy = sdci[9]/10000;
9138 int32_t dw = sdci[10]/10000;
9139 int32_t dh = sdci[11]/10000;
9140 float rot = sdci[12]/10000;
9141 int32_t cx = sdci[13]/10000;
9142 int32_t cy = sdci[14]/10000;
9143 int32_t mode = sdci[15]/10000;
9144 int32_t litcolour = sdci[16]/10000;
9145 bool masked = (sdci[17] != 0);
9146
9147 int32_t ref = 0;
9148
9149 if ( is_bmp && (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
9150 //Do we need to also check the render target and do the same thing if the
9151 //dest == -2 and the render target is not RT_SCREEN?
9152 dx += xoffset;
9153 dy += yoffset;
9154
9155 BITMAP *destbmp = nullptr;
9156 if(is_bmp)
9157 {
9158 ref = sdci[DRAWCMD_BMP_TARGET];
9159
9160 if ( ref <= 0 )
9161 {
9162 Z_scripterrlog("%s wanted to use to an invalid dest bitmap id: %d. Aborting.\n", funcstr, ref);
9163 return;
9164 }
9165 destbmp = FFCore.GetScriptBitmap(ref);
9166 if(!destbmp)
9167 {
9168 Z_message("Warning: %s dest bitmap %d contains invalid data or is not initialized.\n", ref);
9169 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
9170 return;
9171 }
9172 }
9173 else destbmp = bmp;
9174
9175 bool stretched = (sw != dw || sh != dh);
9176
9177 BITMAP* srcbmp = create_bitmap_ex(8, sw, sh);
9178 //Draw tiles to srcbmp
9179 {
9180 clear_bitmap(srcbmp);
9181 int tx = 0, ty = 0;
9182 if(sx < 0)
9183 tx = (sx-15)/16;
9184 else if(sx > 15)
9185 tx = sx/16;
9186 if(sy < 0)
9187 ty = (sy-15)/16;
9188 else if(sy > 15)
9189 ty = sy/16;
9190
9191 int gxoff = -wrap(sx,0,15), gyoff = -wrap(sy,0,15);
9192 for(int ix = 0; ix <= sw; ix += 16)
9193 {
9194 for(int iy = 0; iy <= sh; iy += 16)
9195 {
9196 int t = tile+(tx+ix/16);
9197 int rowdiff = TILEROW(t) - TILEROW(tile);
9198 t += rowdiff * (sh/16) * TILES_PER_ROW;
9199 t += (ty+iy/16)*TILES_PER_ROW;
9200 overtile16(srcbmp, t, ix+gxoff, iy+gyoff, cset, 0);
9201 }
9202 }
9203
9204 sx = sy = 0;
9205 }
9206
9207 BITMAP* subBmp = nullptr;
9208
9209 if(rot != 0 || mode != 0)
9210 {
9211 subBmp = create_bitmap_ex(8,destbmp->w, destbmp->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
9212 clear_bitmap(subBmp);
9213
9214 if(!subBmp)
9215 {
9216 Z_scripterrlog("%s failed to create a sub-bitmap to use for %s. Aborting.\n", funcstr, "rotation");
9217 return;
9218 }
9219 }
9220
9221 //dx = dx + xoffset; //don't do this here!
9222 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
9223
9224 if(stretched)
9225 {
9226 if(masked)
9227 { //stretched and masked
9228 if ( rot == 0 )
9229 { //if not rotated
9230 switch(mode)
9231 {
9232 case 1:
9233 //transparent
9234 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9235 draw_trans_sprite(destbmp, subBmp, dx, dy);
9236 break;
9237
9238
9239 case 2:
9240 //pivot?
9241 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9242 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9243 //Pivoting requires two more args
9244 break;
9245
9246 case 3:
9247 //pivot + trans
9248 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9249 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9250 break;
9251
9252 case 4:
9253 //flip v
9254 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9255 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9256 break;
9257
9258 case 5:
9259 //trans + v flip
9260 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9261 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9262 break;
9263
9264 case 6:
9265 //pivot + v flip
9266 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9267 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9268 break;
9269
9270 case 8:
9271 //vlip h
9272 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9273 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9274 break;
9275
9276 case 9:
9277 //trans + h flip
9278 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9279 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9280 break;
9281
9282 case 10:
9283 //flip H and pivot
9284 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9285 //return error cannot pivot and h flip
9286 break;
9287
9288 case 12:
9289 //vh flip
9290 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9291 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9292 break;
9293
9294 case 13:
9295 //trans + vh flip
9296 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9297 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9298 break;
9299
9300 case 14:
9301 //pivot and vh flip
9302 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9303 //return error cannot both pivot and vh flip
9304 break;
9305
9306 case 16:
9307 //lit
9308 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9309 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9310 break;
9311
9312 case 18:
9313 //pivot, lit
9314 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9315 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9316 break;
9317
9318 case 20:
9319 //lit + v flip
9320 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9321 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9322 break;
9323
9324 case 22:
9325 //Pivot, vflip, lit
9326 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9327 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9328 break;
9329
9330 case 24:
9331 //lit + h flip
9332 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9333 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9334 break;
9335
9336 case 26:
9337 //pivot + lit + hflip
9338 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9339 //return error cannot pivot, lit, and flip
9340 break;
9341
9342 case 28:
9343 //lit + vh flip
9344 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9345 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9346 break;
9347
9348 case 32: //gouraud
9349 //Probably not wort supporting.
9350 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9351 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9352 break;
9353
9354 case 0:
9355 //no effect
9356 masked_stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9357 break;
9358
9359
9360 default:
9361 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9362
9363
9364 }
9365 } //end if not rotated
9366
9367 if ( rot != 0 ) //if rotated
9368 {
9369 switch(mode)
9370 {
9371 case 1:
9372 //transparent
9373 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9374 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9375
9376 break;
9377
9378 case 2:
9379 //pivot?
9380 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9381 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9382 //Pivoting requires two more args
9383 break;
9384
9385 case 3:
9386 //pivot + trans
9387 //return an error, cannot both rotate and pivot
9388 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9389 break;
9390
9391 case 4:
9392 //flip v
9393 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9394 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9395 break;
9396
9397 case 5:
9398 //trans + v flip
9399 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9400 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9401 break;
9402
9403 case 6:
9404 //pivot + v flip
9405 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9406 //return an error, cannot both rotate and pivot
9407 break;
9408
9409 case 8:
9410 //flip h
9411 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9412 //return an error, cannot both rotate and flip H
9413 break;
9414
9415 case 9:
9416 //trans + h flip
9417 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9418 //return an error, cannot rotate and flip a trans sprite
9419 break;
9420
9421 case 10:
9422 //flip H and pivot
9423 //return error cannot pivot and h flip
9424 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9425 break;
9426
9427 case 12:
9428 //vh flip
9429 //return an error, cannot rotate and VH flip a trans sprite
9430 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9431 break;
9432
9433 case 13:
9434 //trans + vh flip
9435 //return an error, cannot rotate and VH flip a trans sprite
9436 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9437 break;
9438
9439 case 14:
9440 //pivot and vh flip
9441 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9442 //return error cannot both pivot and vh flip
9443 break;
9444
9445 case 16:
9446 //lit
9447 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9448 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9449 break;
9450
9451 case 18:
9452 //pivot, lit
9453 //return an error, cannot both rotate and pivot
9454 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9455 break;
9456
9457 case 20:
9458 //lit + vflip
9459 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9460 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9461 break;
9462
9463 case 22:
9464 //Pivot, vflip, lit
9465 //return an error, cannot both rotate and pivot
9466 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9467 break;
9468
9469 case 24:
9470 //lit + h flip
9471 //return an error, cannot both rotate and H flip
9472 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9473 break;
9474
9475 case 26:
9476 //pivot + lit + hflip
9477 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9478 //return error cannot pivot, lit, and flip
9479 break;
9480
9481 case 28:
9482 //lit + vh flip
9483 //return an error, cannot both rotate and VH flip
9484 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9485 break;
9486
9487 case 32: //gouraud
9488 //Probably not wort supporting.
9489 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9490 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9491 break;
9492
9493 case 0:
9494 //no effect.
9495 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9496 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9497 break;
9498
9499 default:
9500 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9501
9502 }
9503 }
9504 } //end if stretched and masked
9505
9506 else //stretched, not masked
9507 {
9508
9509
9510 if ( rot == 0 ) //if not rotated
9511 {
9512 switch(mode)
9513 {
9514 case 1:
9515 //transparent
9516 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9517 draw_trans_sprite(destbmp, subBmp, dx, dy);
9518 break;
9519
9520
9521 case 2:
9522 //pivot?
9523 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9524 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9525 //Pivoting requires two more args
9526 break;
9527
9528 case 3:
9529 //pivot + trans
9530 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9531 pivot_sprite_trans(destbmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
9532 break;
9533
9534 case 4:
9535 //flip v
9536 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9537 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9538 break;
9539
9540 case 5:
9541 //trans + v flip
9542 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9543 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9544 break;
9545
9546 case 6:
9547 //pivot + v flip
9548 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9549 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9550 break;
9551
9552 case 8:
9553 //vlip h
9554 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9555 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9556 break;
9557
9558 case 9:
9559 //trans + h flip
9560 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9561 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9562 break;
9563
9564 case 10:
9565 //flip H and pivot
9566 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9567 //return error cannot pivot and h flip
9568 break;
9569
9570 case 12:
9571 //vh flip
9572 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9573 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9574 break;
9575
9576 case 13:
9577 //trans + vh flip
9578 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9579 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9580 break;
9581
9582 case 14:
9583 //pivot and vh flip
9584 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9585 //return error cannot both pivot and vh flip
9586 break;
9587
9588 case 16:
9589 //lit
9590 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9591 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9592 break;
9593
9594 case 18:
9595 //pivot, lit
9596 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9597 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9598 break;
9599
9600 case 20:
9601 //lit + v flip
9602 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9603 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9604 break;
9605
9606 case 22:
9607 //Pivot, vflip, lit
9608 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9609 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9610 break;
9611
9612 case 24:
9613 //lit + h flip
9614 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9615 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9616 break;
9617
9618 case 26:
9619 //pivot + lit + hflip
9620 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9621 //return error cannot pivot, lit, and flip
9622 break;
9623
9624 case 28:
9625 //lit + vh flip
9626 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9627 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9628 break;
9629
9630 case 32: //gouraud
9631 //Probably not wort supporting.
9632 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9633 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9634 break;
9635
9636 case 0:
9637 //no effect
9638 stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9639 break;
9640
9641
9642 default:
9643 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9644
9645
9646 }
9647 } //end if not rotated
9648
9649 if ( rot != 0 ) //if rotated
9650 {
9651 switch(mode)
9652 {
9653 case 1:
9654 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9655 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9656
9657 break;
9658
9659 case 2:
9660 //pivot?
9661 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9662 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9663 //Pivoting requires two more args
9664 break;
9665
9666 case 3:
9667 //pivot + trans
9668 //return an error, cannot both rotate and pivot
9669 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9670 break;
9671
9672 case 4:
9673 //flip v
9674 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9675 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9676 break;
9677
9678 case 5:
9679 //trans + v flip
9680 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9681 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9682 break;
9683
9684 case 6:
9685 //pivot + v flip
9686 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9687 //return an error, cannot both rotate and pivot
9688 break;
9689
9690 case 8:
9691 //flip h
9692 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9693 //return an error, cannot both rotate and flip H
9694 break;
9695
9696 case 9:
9697 //trans + h flip
9698 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9699 //return an error, cannot rotate and flip a trans sprite
9700 break;
9701
9702 case 10:
9703 //flip H and pivot
9704 //return error cannot pivot and h flip
9705 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9706 break;
9707
9708 case 12:
9709 //vh flip
9710 //return an error, cannot rotate and VH flip a trans sprite
9711 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9712 break;
9713
9714 case 13:
9715 //trans + vh flip
9716 //return an error, cannot rotate and VH flip a trans sprite
9717 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9718 break;
9719
9720 case 14:
9721 //pivot and vh flip
9722 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9723 //return error cannot both pivot and vh flip
9724 break;
9725
9726 case 16:
9727 //lit
9728 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9729 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9730 break;
9731
9732 case 18:
9733 //pivot, lit
9734 //return an error, cannot both rotate and pivot
9735 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9736 break;
9737
9738 case 20:
9739 //lit + vflip
9740 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9741 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9742 break;
9743
9744 case 22:
9745 //Pivot, vflip, lit
9746 //return an error, cannot both rotate and pivot
9747 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9748 break;
9749
9750 case 24:
9751 //lit + h flip
9752 //return an error, cannot both rotate and H flip
9753 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9754 break;
9755
9756 case 26:
9757 //pivot + lit + hflip
9758 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9759 //return error cannot pivot, lit, and flip
9760 break;
9761
9762 case 28:
9763 //lit + vh flip
9764 //return an error, cannot both rotate and VH flip
9765 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9766 break;
9767
9768 case 32: //gouraud
9769 //Probably not wort supporting.
9770 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9771 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9772 break;
9773
9774 case 0:
9775 //no effect.
9776 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9777 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9778 break;
9779
9780 default:
9781 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9782
9783 }
9784 }
9785
9786 } //end if stretched, but not masked
9787 }
9788 else //not stretched
9789 {
9790
9791 if(masked) //if masked, but not stretched
9792 {
9793
9794 if ( rot == 0 ) //if not rotated
9795 {
9796 switch(mode)
9797 {
9798 case 1:
9799 //transparent
9800 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9801 draw_trans_sprite(destbmp, subBmp, dx, dy);
9802 break;
9803
9804
9805 case 2:
9806 //pivot?
9807 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9808 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9809 //Pivoting requires two more args
9810 break;
9811
9812 case 3:
9813 //pivot + trans
9814 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9815 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9816 break;
9817
9818 case 4:
9819 //flip v
9820 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9821 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9822 break;
9823
9824 case 5:
9825 //trans + v flip
9826 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9827 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9828 break;
9829
9830 case 6:
9831 //pivot + v flip
9832 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9833 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9834 break;
9835
9836 case 8:
9837 //vlip h
9838 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9839 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9840 break;
9841
9842 case 9:
9843 //trans + h flip
9844 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9845 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9846 break;
9847
9848 case 10:
9849 //flip H and pivot
9850 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9851 //return error cannot pivot and h flip
9852 break;
9853
9854 case 12:
9855 //vh flip
9856 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9857 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9858 break;
9859
9860 case 13:
9861 //trans + vh flip
9862 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9863 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9864 break;
9865
9866 case 14:
9867 //pivot and vh flip
9868 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9869 //return error cannot both pivot and vh flip
9870 break;
9871
9872 case 16:
9873 //lit
9874 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9875 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9876 break;
9877
9878 case 18:
9879 //pivot, lit
9880 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9881 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9882 break;
9883
9884 case 20:
9885 //lit + v flip
9886 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9887 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9888 break;
9889
9890 case 22:
9891 //Pivot, vflip, lit
9892 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9893 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9894 break;
9895
9896 case 24:
9897 //lit + h flip
9898 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9899 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9900 break;
9901
9902 case 26:
9903 //pivot + lit + hflip
9904 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9905 //return error cannot pivot, lit, and flip
9906 break;
9907
9908 case 28:
9909 //lit + vh flip
9910 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9911 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9912 break;
9913
9914 case 32: //gouraud
9915 //Probably not wort supporting.
9916 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9917 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9918 break;
9919
9920 case 0:
9921 //no effect
9922 masked_blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
9923 break;
9924
9925
9926 default:
9927 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9928
9929
9930 }
9931 } //end if not rotated
9932
9933 if ( rot != 0 ) //if rotated
9934 {
9935 switch(mode)
9936 {
9937 case 1:
9938 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
9939 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9940
9941 break;
9942
9943 case 2:
9944 //pivot?
9945 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9946 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9947 //Pivoting requires two more args
9948 break;
9949
9950 case 3:
9951 //pivot + trans
9952 //return an error, cannot both rotate and pivot
9953 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9954 break;
9955
9956 case 4:
9957 //flip v
9958 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9959 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9960 break;
9961
9962 case 5:
9963 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
9964 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9965 break;
9966
9967 case 6:
9968 //pivot + v flip
9969 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9970 //return an error, cannot both rotate and pivot
9971 break;
9972
9973 case 8:
9974 //flip h
9975 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9976 //return an error, cannot both rotate and flip H
9977 break;
9978
9979 case 9:
9980 //trans + h flip
9981 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9982 //return an error, cannot rotate and flip a trans sprite
9983 break;
9984
9985 case 10:
9986 //flip H and pivot
9987 //return error cannot pivot and h flip
9988 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9989 break;
9990
9991 case 12:
9992 //vh flip
9993 //return an error, cannot rotate and VH flip a trans sprite
9994 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9995 break;
9996
9997 case 13:
9998 //trans + vh flip
9999 //return an error, cannot rotate and VH flip a trans sprite
10000 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10001 break;
10002
10003 case 14:
10004 //pivot and vh flip
10005 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10006 //return error cannot both pivot and vh flip
10007 break;
10008
10009 case 16:
10010 //lit
10011 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10012 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10013 break;
10014
10015 case 18:
10016 //pivot, lit
10017 //return an error, cannot both rotate and pivot
10018 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10019 break;
10020
10021 case 20:
10022 //lit + vflip
10023 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10024 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10025 break;
10026
10027 case 22:
10028 //Pivot, vflip, lit
10029 //return an error, cannot both rotate and pivot
10030 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10031 break;
10032
10033 case 24:
10034 //lit + h flip
10035 //return an error, cannot both rotate and H flip
10036 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10037 break;
10038
10039 case 26:
10040 //pivot + lit + hflip
10041 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10042 //return error cannot pivot, lit, and flip
10043 break;
10044
10045 case 28:
10046 //lit + vh flip
10047 //return an error, cannot both rotate and VH flip
10048 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10049 break;
10050
10051 case 32: //gouraud
10052 //Probably not wort supporting.
10053 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
10054 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10055 break;
10056
10057 case 0:
10058 //no effect.
10059 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10060 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10061 break;
10062
10063 default:
10064 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10065
10066 }
10067 } //end rtated, masked
10068 } //end if masked
10069
10070 else //not masked, and not stretched; just blit
10071 {
10072
10073 if ( rot == 0 ) //if not rotated
10074 {
10075 switch(mode)
10076 {
10077 case 1:
10078 //transparent
10079 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10080 draw_trans_sprite(destbmp, subBmp, dx, dy);
10081 break;
10082
10083
10084 case 2:
10085 //pivot?
10086 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10087 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10088 //Pivoting requires two more args
10089 break;
10090
10091 case 3:
10092 //pivot + trans
10093 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10094 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10095 break;
10096
10097 case 4:
10098 //flip v
10099 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10100 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
10101 break;
10102
10103 case 5:
10104 //trans + v flip
10105 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10106 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
10107 break;
10108
10109 case 6:
10110 //pivot + v flip
10111 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10112 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10113 break;
10114
10115 case 8:
10116 //vlip h
10117 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10118 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
10119 break;
10120
10121 case 9:
10122 //trans + h flip
10123 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10124 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
10125 break;
10126
10127 case 10:
10128 //flip H and pivot
10129 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10130 //return error cannot pivot and h flip
10131 break;
10132
10133 case 12:
10134 //vh flip
10135 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10136 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
10137 break;
10138
10139 case 13:
10140 //trans + vh flip
10141 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10142 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
10143 break;
10144
10145 case 14:
10146 //pivot and vh flip
10147 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10148 //return error cannot both pivot and vh flip
10149 break;
10150
10151 case 16:
10152 //lit
10153 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10154 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
10155 break;
10156
10157 case 18:
10158 //pivot, lit
10159 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10160 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10161 break;
10162
10163 case 20:
10164 //lit + v flip
10165 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10166 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
10167 break;
10168
10169 case 22:
10170 //Pivot, vflip, lit
10171 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10172 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10173 break;
10174
10175 case 24:
10176 //lit + h flip
10177 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10178 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
10179 break;
10180
10181 case 26:
10182 //pivot + lit + hflip
10183 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
10184 //return error cannot pivot, lit, and flip
10185 break;
10186
10187 case 28:
10188 //lit + vh flip
10189 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10190 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
10191 break;
10192
10193 case 32: //gouraud
10194 //Probably not wort supporting.
10195 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10196 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10197 break;
10198
10199 case 0:
10200 //no effect
10201 blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10202 break;
10203
10204
10205 default:
10206 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10207
10208
10209 }
10210 } //end if not rotated
10211
10212 if ( rot != 0 ) //if rotated
10213 {
10214 switch(mode)
10215 {
10216 case 1:
10217 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
10218 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10219
10220 break;
10221
10222 case 2:
10223 //pivot?
10224 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10225 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10226 //Pivoting requires two more args
10227 break;
10228
10229 case 3:
10230 //pivot + trans
10231 //return an error, cannot both rotate and pivot
10232 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10233 break;
10234
10235 case 4:
10236 //flip v
10237 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10238 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10239 break;
10240
10241 case 5:
10242 //trans + v flip
10243 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10244 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10245 break;
10246
10247 case 6:
10248 //pivot + v flip
10249 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10250 //return an error, cannot both rotate and pivot
10251 break;
10252
10253 case 8:
10254 //flip h
10255 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10256 //return an error, cannot both rotate and flip H
10257 break;
10258
10259 case 9:
10260 //trans + h flip
10261 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10262 //return an error, cannot rotate and flip a trans sprite
10263 break;
10264
10265 case 10:
10266 //flip H and pivot
10267 //return error cannot pivot and h flip
10268 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10269 break;
10270
10271 case 12:
10272 //vh flip
10273 //return an error, cannot rotate and VH flip a trans sprite
10274 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10275 break;
10276
10277 case 13:
10278 //trans + vh flip
10279 //return an error, cannot rotate and VH flip a trans sprite
10280 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10281 break;
10282
10283 case 14:
10284 //pivot and vh flip
10285 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10286 //return error cannot both pivot and vh flip
10287 break;
10288
10289 case 16:
10290 //lit
10291 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10292 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10293 break;
10294
10295 case 18:
10296 //pivot, lit
10297 //return an error, cannot both rotate and pivot
10298 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10299 break;
10300
10301 case 20:
10302 //lit + vflip
10303 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10304 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10305 break;
10306
10307 case 22:
10308 //Pivot, vflip, lit
10309 //return an error, cannot both rotate and pivot
10310 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10311 break;
10312
10313 case 24:
10314 //lit + h flip
10315 //return an error, cannot both rotate and H flip
10316 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10317 break;
10318
10319 case 26:
10320 //pivot + lit + hflip
10321 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10322 //return error cannot pivot, lit, and flip
10323 break;
10324
10325 case 28:
10326 //lit + vh flip
10327 //return an error, cannot both rotate and VH flip
10328 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10329 break;
10330
10331 case 32: //gouraud
10332 //Probably not wort supporting.
10333 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10334 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10335 break;
10336
10337 case 0:
10338 //no effect.
10339 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10340 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10341 break;
10342
10343 default:
10344 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10345
10346 }
10347 } //end if rotated
10348 } //end if not masked
10349 } //end if not stretched
10350
10351 //cleanup
10352 if(subBmp)
10353 {
10354 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
10355 destroy_bitmap(subBmp);
10356 }
10357 destroy_bitmap(srcbmp);
10358 }
10359
10360 void do_comboblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp)
10361 {
10362 //sdci[2]: combo -> tile
10363 int cid = sdci[2]/10000;
10364 if(unsigned(cid) >= MAXCOMBOS)
10365 {
10366 Z_scripterrlog("ComboBlit tried to draw invalid combo id '%d'\n", cid);
10367 return;
10368 }
10369 sdci[2] = combobuf[cid].tile * 10000;
10370 do_tileblit(bmp, sdci, xoffset, yoffset, is_bmp, "ComboBlit()");
10371 }
10372
10373 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10374 {
10375
10376 //sdci[1]=layer
10377 //sdci[2]=pos[12]
10378 //sdci[3]=uv[8]
10379 //sdci[4]=color[4]
10380 //sdci[5]=size[2]
10381 //sdci[6]=flip
10382 //sdci[7]=tile/combo
10383 //sdci[8]=polytype
10384 //sdci[9] = other bitmap as texture
10385 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10386 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10387 {
10388 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10389 return;
10390 }
10391 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10392 if ( refbmp == NULL ) return;
10393
10394 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10395
10396 if(!v_ptr)
10397 {
10398 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
10399 return;
10400 }
10401
10402 std::vector<int32_t> &v = *v_ptr;
10403
10404 if(v.empty())
10405 return;
10406
10407 int32_t* pos = &v[0];
10408 int32_t* uv = &v[12];
10409 int32_t* col = &v[20];
10410 int32_t* size = &v[24];
10411
10412 int32_t w = size[0]; //magic numerical constants... yuck.
10413 int32_t h = size[1];
10414 int32_t flip = (sdci[6]/10000)&3;
10415 int32_t tile = sdci[7]/10000;
10416 int32_t polytype = sdci[8]/10000;
10417 int32_t quad_render_source = sdci[9];
10418 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
10419
10420 polytype = vbound(polytype, 0, 14);
10421
10422 int32_t tex_width = w*16;
10423 int32_t tex_height = h*16;
10424
10425 bool mustDestroyBmp = false;
10426 BITMAP *tex=NULL;
10427
10428
10429 bool tex_is_bitmap = ( sdci[9] != 0 );
10430 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
10431 //Z_scripterrlog("sdci[DRAWCMD_BMP_TARGET] is %d\n", sdci[DRAWCMD_BMP_TARGET]);
10432 BITMAP *bmptexture;
10433
10434 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10435
10436 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10437
10438
10439 if ( !tex_is_bitmap )
10440 {
10441 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10442
10443 if(!tex)
10444 {
10445 mustDestroyBmp = true;
10446 tex = create_bitmap_ex(8, tex_width, tex_height);
10447 clear_bitmap(tex);
10448 }
10449 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10450 {
10451 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10452 return; //non power of two error
10453 }
10454 if(tile > 0) // TILE
10455 {
10456 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10457 }
10458 else // COMBO
10459 {
10460 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
10461 const int32_t tiletodraw = combo_tile(c, 0, 0);
10462 flip = flip ^ c.flip;
10463
10464 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10465 }
10466
10467 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10468 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10469 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10470 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10471
10472 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
10473 if(mustDestroyBmp)
10474 destroy_bitmap(tex);
10475 }
10476 else
10477 {
10478
10479 if ( !bmptexture )
10480 {
10481 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
10482 tex_is_bitmap = 0;
10483 return;
10484 }
10485 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10486 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10487 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10488 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10489
10490 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10491 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10492 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10493 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10494
10495 BITMAP *foo = create_bitmap_ex(8, 256, 176);
10496
10497 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
10498 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
10499 destroy_bitmap(foo);
10500
10501 }
10502
10503
10504
10505 }
10506
10507
10508
10509 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10510 {
10511 //sdci[1]=layer
10512 //sdci[2]=pos[9]
10513 //sdci[3]=uv[6]
10514 //sdci[4]=color[3]
10515 //sdci[5]=size[2]
10516 //sdci[6]=flip
10517 //sdci[7]=tile/combo
10518 //sdci[8]=polytype
10519 //sdci[9] bitmap as texture
10520 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10521 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10522 {
10523 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10524 return;
10525 }
10526 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10527 if ( refbmp == NULL ) return;
10528
10529 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10530
10531 if(!v_ptr)
10532 {
10533 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
10534 return;
10535 }
10536
10537 std::vector<int32_t> &v = *v_ptr;
10538
10539 if(v.empty())
10540 return;
10541
10542 int32_t* pos = &v[0];
10543 int32_t* uv = &v[9];
10544 int32_t* col = &v[15];
10545 int32_t* size = &v[18];
10546
10547 int32_t w = size[0]; //magic numerical constants... yuck.
10548 int32_t h = size[1];
10549 int32_t flip = (sdci[6]/10000)&3;
10550 int32_t tile = sdci[7]/10000;
10551 int32_t polytype = sdci[8]/10000;
10552 int32_t quad_render_source = sdci[9];
10553 polytype = vbound(polytype, 0, 14);
10554
10555 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10556 {
10557 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10558 return; //non power of two error
10559 }
10560
10561 int32_t tex_width = w*16;
10562 int32_t tex_height = h*16;
10563
10564 bool mustDestroyBmp = false;
10565 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10566
10567 if(!tex)
10568 {
10569 mustDestroyBmp = true;
10570 tex = create_bitmap_ex(8, tex_width, tex_height);
10571 clear_bitmap(tex);
10572 }
10573
10574 bool tex_is_bitmap = ( sdci[9] != 0 );
10575 BITMAP *bmptexture=NULL;
10576 if ( tex_is_bitmap )
10577 {
10578 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10579 if ( !bmptexture )
10580 {
10581 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
10582 tex_is_bitmap = 0;
10583 }
10584 }
10585
10586 if ( !tex_is_bitmap )
10587 {
10588 if(tile > 0) // TILE
10589 {
10590 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10591 }
10592 else // COMBO
10593 {
10594 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
10595 const int32_t tiletodraw = combo_tile(c, 0, 0);
10596 flip = flip ^ c.flip;
10597
10598 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10599 }
10600
10601 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10602 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10603 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10604
10605 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
10606 }
10607 else
10608 {
10609 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10610 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10611 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10612 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10613
10614 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10615 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10616 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10617
10618 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
10619
10620
10621 }
10622 if(mustDestroyBmp)
10623 destroy_bitmap(tex);
10624
10625 }
10626
10627
10628 bool is_layer_transparent(const mapscr& m, int32_t layer)
10629 {
10630 layer = vbound(layer, 0, 5);
10631 return m.layeropacity[layer] == 128;
10632 }
10633
10634 4336942 mapscr *getmapscreen(int32_t map_index, int32_t screen_index, int32_t layer) //returns NULL for invalid or non-existent layer
10635 {
10636 mapscr *base_screen;
10637 4336942 int32_t index = map_index*MAPSCRS+screen_index;
10638
10639
2/4
✓ Branch 0 taken 4336942 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4336942 times.
4336942 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
10640 return NULL;
10641
10642
2/2
✓ Branch 0 taken 3552036 times.
✓ Branch 1 taken 784906 times.
4336942 if(layer != 0)
10643 {
10644 784906 layer = layer - 1;
10645
10646 784906 base_screen=&(TheMaps[index]);
10647
10648
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_screen->layermap[layer]==0)
10649 36727 return NULL;
10650
10651 748179 index=(base_screen->layermap[layer]-1)*MAPSCRS+base_screen->layerscreen[layer];
10652
10653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
10654 return NULL;
10655 748179 }
10656
10657 4300215 return &(TheMaps[index]);
10658 4336942 }
10659
10660 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
10661 {
10662
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
10663 {
10664 33714560 const int32_t x2 = ((i&15)<<4) + x;
10665 33714560 const int32_t y2 = (i&0xF0) + y;
10666
10667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent)
10668 {
10669 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
10670 }
10671 else
10672 {
10673 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
10674 }
10675 33714560 }
10676 191560 }
10677
10678 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10679 {
10680 BITMAP* square = create_bitmap_ex(8,16,16);
10681
10682 for(int32_t i(0); i < 176; ++i)
10683 {
10684 const int32_t x2 = ((i&15)<<4) + x;
10685 const int32_t y2 = (i&0xF0) + y;
10686 //Blit the palette index of the solidity value.
10687 clear_to_color(square,(combobuf[m.data[i]].walk&15));
10688 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10689 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10690 }
10691 destroy_bitmap(square);
10692 }
10693
10694 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10695 {
10696 //sdci[1]=layer
10697 //sdci[2]=map
10698 //sdci[3]=screen
10699 //sdci[4]=x
10700 //sdci[5]=y
10701 //sdci[6]=rotation
10702 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10703
10704 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10705 if ( refbmp == NULL ) return;
10706
10707 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10708
10709 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10710 int32_t scrn = sdci[3]/10000;
10711 int32_t x = sdci[4]/10000;
10712 int32_t y = sdci[5]/10000;
10713 int32_t x1 = x + xoffset;
10714 int32_t y1 = y + yoffset;
10715 int32_t rotation = sdci[6]/10000;
10716
10717 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10718
10719 if(index >= TheMaps.size())
10720 {
10721 al_trace("DrawScreen: invalid map or screen index. \n");
10722 return;
10723 }
10724
10725 const mapscr & m = TheMaps[index];
10726
10727
10728 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10729 if ( refbmp == NULL ) return;
10730
10731 if(rotation != 0)
10732 b = script_drawing_commands.AquireSubBitmap(256, 176);
10733
10734 //draw layer 0
10735 draw_map_solidity(b, m, x1, y1);
10736 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10737 {
10738 for(int32_t i(0); i < 6; ++i)
10739 {
10740 if(m.layermap[i] == 0) continue;
10741
10742 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10743
10744 if(layer_screen_index >= TheMaps.size())
10745 continue;
10746
10747 //draw valid layers
10748 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
10749 }
10750 }
10751
10752 if(rotation != 0) // rotate
10753 {
10754 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10755 script_drawing_commands.ReleaseSubBitmap(b);
10756 }
10757 }
10758
10759 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10760 {
10761 BITMAP* square = create_bitmap_ex(8,16,16);
10762 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10763 clear_to_color(subsquare,1);
10764
10765 for(int32_t i(0); i < 176; ++i)
10766 {
10767 const int32_t x2 = ((i&15)<<4) + x;
10768 const int32_t y2 = (i&0xF0) + y;
10769 //Blit the palette index of the solidity value.
10770 clear_bitmap(square);
10771 int32_t sol = (combobuf[m.data[i]].walk);
10772 if ( sol & 1 )
10773 {
10774 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10775 }
10776 if ( sol & 2 )
10777 {
10778 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10779 }
10780 if ( sol & 4 )
10781 {
10782 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10783 }
10784 if ( sol &8 ) {
10785 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10786 }
10787
10788 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10789 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10790 }
10791 destroy_bitmap(square);
10792 destroy_bitmap(subsquare);
10793 }
10794
10795 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10796 {
10797 //sdci[1]=layer
10798 //sdci[2]=map
10799 //sdci[3]=screen
10800 //sdci[4]=x
10801 //sdci[5]=y
10802 //sdci[6]=rotation
10803 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10804
10805 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10806 if ( refbmp == NULL ) return;
10807
10808 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10809
10810 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10811 int32_t scrn = sdci[3]/10000;
10812 int32_t x = sdci[4]/10000;
10813 int32_t y = sdci[5]/10000;
10814 int32_t x1 = x + xoffset;
10815 int32_t y1 = y + yoffset;
10816 int32_t rotation = sdci[6]/10000;
10817
10818 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10819
10820 if(index >= TheMaps.size())
10821 {
10822 al_trace("DrawScreen: invalid map or screen index. \n");
10823 return;
10824 }
10825
10826 const mapscr & m = TheMaps[index];
10827
10828
10829 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10830 if ( refbmp == NULL ) return;
10831
10832 if(rotation != 0)
10833 b = script_drawing_commands.AquireSubBitmap(256, 176);
10834
10835 //draw layer 0
10836 draw_map_solid(b, m, x1, y1);
10837
10838 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
10839 {
10840 if(m.layermap[i] == 0) continue;
10841
10842 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10843
10844 if(layer_screen_index >= TheMaps.size())
10845 continue;
10846
10847 //draw valid layers
10848 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
10849 }
10850
10851 if(rotation != 0) // rotate
10852 {
10853 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10854 script_drawing_commands.ReleaseSubBitmap(b);
10855 }
10856 }
10857
10858 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10859 {
10860 1024 BITMAP* square = create_bitmap_ex(8,16,16);
10861
10862
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
10863 {
10864 180224 const int32_t x2 = ((i&15)<<4) + x;
10865 180224 const int32_t y2 = (i&0xF0) + y;
10866 //Blit the palette index of the solidity value.
10867 180224 clear_to_color(square,m.sflag[i]);
10868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10869 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10870 180224 }
10871 1024 destroy_bitmap(square);
10872 1024 }
10873
10874 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10875 {
10876 //sdci[1]=layer
10877 //sdci[2]=map
10878 //sdci[3]=screen
10879 //sdci[4]=x
10880 //sdci[5]=y
10881 //sdci[6]=rotation
10882 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10883
10884 1024 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10885
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10886
10887
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10888
10889 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10890 1024 int32_t scrn = sdci[3]/10000;
10891 1024 int32_t x = sdci[4]/10000;
10892 1024 int32_t y = sdci[5]/10000;
10893 1024 int32_t x1 = x + xoffset;
10894 1024 int32_t y1 = y + yoffset;
10895 1024 int32_t rotation = sdci[6]/10000;
10896
10897 1024 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10898
10899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
10900 {
10901 al_trace("DrawScreen: invalid map or screen index. \n");
10902 return;
10903 }
10904
10905 1024 const mapscr & m = TheMaps[index];
10906
10907
10908 1024 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10909
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10910
10911
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
10912 b = script_drawing_commands.AquireSubBitmap(256, 176);
10913
10914 //draw layer 0
10915 1024 draw_map_cflag(b, m, x1, y1);
10916
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10917 {
10918 for(int32_t i(0); i < 6; ++i)
10919 {
10920 if(m.layermap[i] == 0) continue;
10921
10922 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10923
10924 if(layer_screen_index >= TheMaps.size())
10925 continue;
10926
10927 //draw valid layers
10928 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
10929 }
10930 }
10931
10932
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
10933 {
10934 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10935 script_drawing_commands.ReleaseSubBitmap(b);
10936 }
10937 1024 }
10938
10939
10940 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10941 {
10942 BITMAP* square = create_bitmap_ex(8,16,16);
10943
10944 for(int32_t i(0); i < 176; ++i)
10945 {
10946 const int32_t x2 = ((i&15)<<4) + x;
10947 const int32_t y2 = (i&0xF0) + y;
10948 //Blit the palette index of the solidity value.
10949 clear_to_color(square,(combobuf[m.data[i]].type));
10950 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10951 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10952 }
10953 destroy_bitmap(square);
10954 }
10955
10956 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10957 {
10958 //sdci[1]=layer
10959 //sdci[2]=map
10960 //sdci[3]=screen
10961 //sdci[4]=x
10962 //sdci[5]=y
10963 //sdci[6]=rotation
10964 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10965
10966 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10967 if ( refbmp == NULL ) return;
10968
10969 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10970
10971 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10972 int32_t scrn = sdci[3]/10000;
10973 int32_t x = sdci[4]/10000;
10974 int32_t y = sdci[5]/10000;
10975 int32_t x1 = x + xoffset;
10976 int32_t y1 = y + yoffset;
10977 int32_t rotation = sdci[6]/10000;
10978
10979 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10980
10981 if(index >= TheMaps.size())
10982 {
10983 al_trace("DrawScreen: invalid map or screen index. \n");
10984 return;
10985 }
10986
10987 const mapscr & m = TheMaps[index];
10988
10989
10990 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10991 if ( refbmp == NULL ) return;
10992
10993 if(rotation != 0)
10994 b = script_drawing_commands.AquireSubBitmap(256, 176);
10995
10996 //draw layer 0
10997 draw_map_combotype(b, m, x1, y1);
10998
10999 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11000 {
11001 for(int32_t i(0); i < 6; ++i)
11002 {
11003 if(m.layermap[i] == 0) continue;
11004
11005 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11006
11007 if(layer_screen_index >= TheMaps.size())
11008 continue;
11009
11010 //draw valid layers
11011 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
11012 }
11013 }
11014
11015 if(rotation != 0) // rotate
11016 {
11017 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11018 script_drawing_commands.ReleaseSubBitmap(b);
11019 }
11020 }
11021
11022
11023 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11024 {
11025 BITMAP* square = create_bitmap_ex(8,16,16);
11026
11027 for(int32_t i(0); i < 176; ++i)
11028 {
11029 const int32_t x2 = ((i&15)<<4) + x;
11030 const int32_t y2 = (i&0xF0) + y;
11031 //Blit the palette index of the solidity value.
11032 clear_to_color(square,(combobuf[m.data[i]].flag));
11033 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11034 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11035 }
11036 destroy_bitmap(square);
11037 }
11038
11039 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11040 {
11041 //sdci[1]=layer
11042 //sdci[2]=map
11043 //sdci[3]=screen
11044 //sdci[4]=x
11045 //sdci[5]=y
11046 //sdci[6]=rotation
11047 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11048
11049 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11050 if ( refbmp == NULL ) return;
11051
11052 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11053
11054 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11055 int32_t scrn = sdci[3]/10000;
11056 int32_t x = sdci[4]/10000;
11057 int32_t y = sdci[5]/10000;
11058 int32_t x1 = x + xoffset;
11059 int32_t y1 = y + yoffset;
11060 int32_t rotation = sdci[6]/10000;
11061
11062 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11063
11064 if(index >= TheMaps.size())
11065 {
11066 al_trace("DrawScreen: invalid map or screen index. \n");
11067 return;
11068 }
11069
11070 const mapscr & m = TheMaps[index];
11071
11072
11073 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11074 if ( refbmp == NULL ) return;
11075
11076 if(rotation != 0)
11077 b = script_drawing_commands.AquireSubBitmap(256, 176);
11078
11079 //draw layer 0
11080 draw_map_comboiflag(b, m, x1, y1);
11081
11082 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11083 {
11084 for(int32_t i(0); i < 6; ++i)
11085 {
11086 if(m.layermap[i] == 0) continue;
11087
11088 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11089
11090 if(layer_screen_index >= TheMaps.size())
11091 continue;
11092
11093 //draw valid layers
11094 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
11095 }
11096 }
11097
11098 if(rotation != 0) // rotate
11099 {
11100 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11101 script_drawing_commands.ReleaseSubBitmap(b);
11102 }
11103 }
11104
11105 4335769 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11106 {
11107 //sdci[1]=layer
11108 //sdci[2]=map
11109 //sdci[3]=screen
11110 //sdci[4]=layer
11111 //sdci[5]=x
11112 //sdci[6]=y
11113 //sdci[7]=rotation
11114 //sdci[8]=opacity
11115
11116 4335769 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11117 4335769 int32_t scrn = sdci[3]/10000;
11118 4335769 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11119 4335769 int32_t x = sdci[5]/10000;
11120 4335769 int32_t y = sdci[6]/10000;
11121 4335769 int32_t x1 = x + xoffset;
11122 4335769 int32_t y1 = y + yoffset;
11123 4335769 int32_t rotation = sdci[7]/10000;
11124 4335769 int32_t opacity = sdci[8]/10000;
11125
11126 4335769 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11127 4335769 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11128
11129
2/2
✓ Branch 0 taken 4299048 times.
✓ Branch 1 taken 36721 times.
4335769 if(!m) //no need to log it.
11130 36721 return;
11131
11132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(index >= TheMaps.size())
11133 {
11134 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11135 return;
11136 }
11137
11138 4299048 const mapscr & l = *m;
11139
11140 4299048 BITMAP* b = bmp;
11141
11142
1/2
✓ Branch 0 taken 4299048 times.
✗ Branch 1 not taken.
4299048 if(rotation != 0)
11143 b = script_drawing_commands.AquireSubBitmap(256, 176);
11144
11145
11146 4299048 const int32_t maxX = isOffScreen ? 512 : 256;
11147
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 18109 times.
4299048 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11148 4299048 bool transparent = opacity <= 128;
11149
11150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(rotation != 0) // rotate
11151 {
11152 draw_mapscr(b, l, x1, y1, transparent);
11153
11154 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11155 script_drawing_commands.ReleaseSubBitmap(b);
11156 }
11157 else
11158 {
11159
2/2
✓ Branch 0 taken 756632448 times.
✓ Branch 1 taken 4299048 times.
760931496 for(int32_t i(0); i < 176; ++i)
11160 {
11161 756632448 const int32_t x2 = ((i&15)<<4) + x1;
11162 756632448 const int32_t y2 = (i&0xF0) + y1;
11163
11164
7/8
✓ Branch 0 taken 666127814 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666127814 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611722422 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602566680 times.
756632448 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
11165 {
11166 602566680 const newcombo & c = combobuf[ l.data[i] ];
11167 602566680 const int32_t tile = combo_tile(c, x2, y2);
11168
11169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602566680 times.
602566680 if(opacity < 128)
11170 {
11171 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
11172
11173
11174 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
11175 }
11176 else
11177 {
11178 602566680 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
11179 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
11180 }
11181 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11182 602566680 }
11183 756632448 }
11184 }
11185
11186 //putscr
11187 4335769 }
11188
11189
11190
11191 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11192 {
11193 //sdci[1]=layer
11194 //sdci[2]=map
11195 //sdci[3]=screen
11196 //sdci[4]=x
11197 //sdci[5]=y
11198 //sdci[6]=rotation
11199
11200 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11201 50406 int32_t scrn = sdci[3]/10000;
11202 50406 int32_t x = sdci[4]/10000;
11203 50406 int32_t y = sdci[5]/10000;
11204 50406 int32_t x1 = x + xoffset;
11205 50406 int32_t y1 = y + yoffset;
11206 50406 int32_t rotation = sdci[6]/10000;
11207
11208 50406 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11209
11210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
11211 {
11212 al_trace("DrawScreen: invalid map or screen index. \n");
11213 return;
11214 }
11215
11216 50406 const mapscr & m = TheMaps[index];
11217
11218
11219 50406 BITMAP* b = bmp;
11220
11221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
11222 b = script_drawing_commands.AquireSubBitmap(256, 176);
11223
11224 //draw layer 0
11225 50406 draw_mapscr(b, m, x1, y1, false);
11226
11227
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
11228 {
11229
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
11230
11231 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11232
11233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
11234 continue;
11235
11236 137944 bool trans = m.layeropacity[i] == 128;
11237
11238 //draw valid layers
11239 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11240 137944 }
11241
11242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
11243 {
11244 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11245 script_drawing_commands.ReleaseSubBitmap(b);
11246 }
11247 50406 }
11248
11249
11250 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11251 {
11252 //sdci[1]=layer
11253 //sdci[2]=map
11254 //sdci[3]=screen
11255 //sdci[4]=layer
11256 //sdci[5]=x
11257 //sdci[6]=y
11258 //sdci[7]=rotation
11259 //[8] noclip
11260 //sdci[9]=opacity
11261 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11262
11263 1173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11264
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
11265
11266 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11267 1173 int32_t scrn = sdci[3]/10000;
11268 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11269 1173 int32_t x = sdci[5]/10000;
11270 1173 int32_t y = sdci[6]/10000;
11271 1173 int32_t rotation = sdci[7]/10000;
11272
11273 1173 byte noclip = 0;//(sdci[8]!=0);
11274 1173 int32_t opacity = sdci[8]/10000;
11275 1173 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11276 1173 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11277
11278
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
11279 6 return;
11280
11281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
11282 {
11283 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
11284 return;
11285 }
11286
11287 1167 const mapscr & l = *m;
11288
11289 1167 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11290
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
11291
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11292
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
11293 b = script_drawing_commands.AquireSubBitmap(256, 176);
11294
11295
11296 1167 const int32_t maxX = isOffScreen ? 512 : 256;
11297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11298 1167 bool transparent = opacity <= 128;
11299
11300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
11301 {
11302 draw_mapscr(b, l, x, y, transparent);
11303
11304 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
11305 script_drawing_commands.ReleaseSubBitmap(b);
11306 }
11307 else
11308 {
11309
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
11310 {
11311 205392 const int32_t x2 = ((i&15)<<4) + x;
11312 205392 const int32_t y2 = (i&0xF0) + y;
11313
11314 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11315 {
11316 205392 const newcombo & c = combobuf[ l.data[i] ];
11317 205392 const int32_t tile = combo_tile(c, x2, y2);
11318
11319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128)
11320 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
11321 else
11322 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
11323
11324 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11325 }
11326 205392 }
11327 }
11328
11329 //putscr
11330 1173 }
11331
11332
11333
11334 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11335 {
11336 //sdci[1]=layer
11337 //sdci[2]=map
11338 //sdci[3]=screen
11339 //sdci[4]=x
11340 //sdci[5]=y
11341 //sdci[6]=rotation
11342 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11343
11344 1092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11345
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
11346
11347
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11348
11349 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11350 1092 int32_t scrn = sdci[3]/10000;
11351 1092 int32_t x = sdci[4]/10000;
11352 1092 int32_t y = sdci[5]/10000;
11353 1092 int32_t x1 = x + xoffset;
11354 1092 int32_t y1 = y + yoffset;
11355 1092 int32_t rotation = sdci[6]/10000;
11356
11357 1092 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11358
11359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
11360 {
11361 al_trace("DrawScreen: invalid map or screen index. \n");
11362 return;
11363 }
11364
11365 1092 const mapscr & m = TheMaps[index];
11366
11367
11368 1092 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
11370
11371
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
11372 b = script_drawing_commands.AquireSubBitmap(256, 176);
11373
11374 //draw layer 0
11375 1092 draw_mapscr(b, m, x1, y1, false);
11376
11377
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
11378 {
11379
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
11380
11381 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11382
11383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
11384 continue;
11385
11386 2118 bool trans = m.layeropacity[i] == 128;
11387
11388 //draw valid layers
11389 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11390 2118 }
11391
11392
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
11393 {
11394 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11395 script_drawing_commands.ReleaseSubBitmap(b);
11396 }
11397 1092 }
11398
11399 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11400 {
11401 //sdci[1]=layer
11402 //sdci[2]=map
11403 //sdci[3]=screen
11404 //sdci[4]=layer
11405 //sdci[5]=x
11406 //sdci[6]=y
11407 //sdci[7]=rotation
11408 //sdci[8]=bool noclip
11409 //sdci[9] == opacity
11410
11411 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11412 int32_t scrn = sdci[3]/10000;
11413 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11414 int32_t x = sdci[5]/10000;
11415 int32_t y = sdci[6]/10000;
11416 int32_t x1 = x + xoffset;
11417 int32_t y1 = y + yoffset;
11418 int32_t rotation = sdci[7]/10000;
11419 byte noclip = (sdci[8]!=0);
11420 int32_t opacity = sdci[9]/10000;
11421
11422 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11423 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11424
11425 if(!m) //no need to log it.
11426 return;
11427
11428 if(index >= TheMaps.size())
11429 {
11430 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11431 return;
11432 }
11433
11434 const mapscr & l = *m;
11435
11436 BITMAP* b = bmp;
11437
11438 if(rotation != 0)
11439 b = script_drawing_commands.AquireSubBitmap(256, 176);
11440
11441
11442 const int32_t maxX = isOffScreen ? 512 : 256;
11443 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11444 bool transparent = opacity <= 128;
11445
11446 if(rotation != 0) // rotate
11447 {
11448 draw_map_solid(b, l, x1, y1);
11449
11450 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11451 script_drawing_commands.ReleaseSubBitmap(b);
11452 }
11453 else
11454 {
11455 BITMAP* square = create_bitmap_ex(8,16,16);
11456 BITMAP* subsquare = create_bitmap_ex(8,16,16);
11457 clear_to_color(subsquare,1);
11458 for(int32_t i(0); i < 176; ++i)
11459 {
11460 const int32_t x2 = ((i&15)<<4) + x1;
11461 const int32_t y2 = (i&0xF0) + y1;
11462
11463 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11464 {
11465 int32_t sol = (combobuf[l.data[i]].walk);
11466
11467 if ( sol & 1 )
11468 {
11469 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
11470 }
11471 if ( sol & 2 )
11472 {
11473 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
11474 }
11475 if ( sol & 4 )
11476 {
11477 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
11478 }
11479 if ( sol &8 ) {
11480 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
11481 }
11482
11483 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11484 }
11485 }
11486 destroy_bitmap(square);
11487 destroy_bitmap(subsquare);
11488 }
11489
11490 //putscr
11491 }
11492
11493 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11494 {
11495 //sdci[1]=layer
11496 //sdci[2]=map
11497 //sdci[3]=screen
11498 //sdci[4]=layer
11499 //sdci[5]=x
11500 //sdci[6]=y
11501 //sdci[7]=rotation
11502 //[8] noclip
11503 //sdci[9]=opacity
11504
11505
11506 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11507 int32_t scrn = sdci[3]/10000;
11508 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11509 int32_t x = sdci[5]/10000;
11510 int32_t y = sdci[6]/10000;
11511 int32_t x1 = x + xoffset;
11512 int32_t y1 = y + yoffset;
11513 int32_t rotation = sdci[7]/10000;
11514 byte noclip = (sdci[8]!=0);
11515 int32_t opacity = sdci[9]/10000;
11516
11517 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11518 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11519
11520 if(!m) //no need to log it.
11521 return;
11522
11523 if(index >= TheMaps.size())
11524 {
11525 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11526 return;
11527 }
11528
11529 const mapscr & l = *m;
11530
11531 BITMAP* b = bmp;
11532
11533 if(rotation != 0)
11534 b = script_drawing_commands.AquireSubBitmap(256, 176);
11535
11536
11537 const int32_t maxX = isOffScreen ? 512 : 256;
11538 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11539 bool transparent = opacity <= 128;
11540
11541 if(rotation != 0) // rotate
11542 {
11543 draw_map_solidity(b, l, x1, y1);
11544
11545 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11546 script_drawing_commands.ReleaseSubBitmap(b);
11547 }
11548 else
11549 {
11550 BITMAP* square = create_bitmap_ex(8,16,16);
11551 for(int32_t i(0); i < 176; ++i)
11552 {
11553 const int32_t x2 = ((i&15)<<4) + x1;
11554 const int32_t y2 = (i&0xF0) + y1;
11555
11556 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11557 {
11558 clear_to_color(square,(combobuf[l.data[i]].walk&15));
11559 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11560 }
11561 }
11562 destroy_bitmap(square);
11563 }
11564
11565 //putscr
11566 }
11567
11568 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11569 {
11570 //sdci[1]=layer
11571 //sdci[2]=map
11572 //sdci[3]=screen
11573 //sdci[4]=layer
11574 //sdci[5]=x
11575 //sdci[6]=y
11576 //sdci[7]=rotation
11577 //[8] noclip
11578 //sdci[9]=opacity
11579
11580
11581 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11582 int32_t scrn = sdci[3]/10000;
11583 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11584 int32_t x = sdci[5]/10000;
11585 int32_t y = sdci[6]/10000;
11586 int32_t x1 = x + xoffset;
11587 int32_t y1 = y + yoffset;
11588 int32_t rotation = sdci[7]/10000;
11589
11590 byte noclip = (sdci[8]!=0);
11591 int32_t opacity = sdci[9]/10000;
11592
11593 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11594 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11595
11596 if(!m) //no need to log it.
11597 return;
11598
11599 if(index >= TheMaps.size())
11600 {
11601 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11602 return;
11603 }
11604
11605 const mapscr & l = *m;
11606
11607 BITMAP* b = bmp;
11608
11609 if(rotation != 0)
11610 b = script_drawing_commands.AquireSubBitmap(256, 176);
11611
11612
11613 const int32_t maxX = isOffScreen ? 512 : 256;
11614 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11615 bool transparent = opacity <= 128;
11616
11617 if(rotation != 0) // rotate
11618 {
11619 draw_map_cflag(b, l, x1, y1);
11620
11621 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11622 script_drawing_commands.ReleaseSubBitmap(b);
11623 }
11624 else
11625 {
11626 BITMAP* square = create_bitmap_ex(8,16,16);
11627 for(int32_t i(0); i < 176; ++i)
11628 {
11629 const int32_t x2 = ((i&15)<<4) + x1;
11630 const int32_t y2 = (i&0xF0) + y1;
11631
11632 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11633 {
11634 clear_to_color(square,l.sflag[i]);
11635 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11636 }
11637 }
11638 destroy_bitmap(square);
11639 }
11640
11641 //putscr
11642 }
11643
11644 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11645 {
11646 //sdci[1]=layer
11647 //sdci[2]=map
11648 //sdci[3]=screen
11649 //sdci[4]=layer
11650 //sdci[5]=x
11651 //sdci[6]=y
11652 //sdci[7]=rotation
11653 //[8] noclip
11654 //sdci[9]=opacity
11655
11656 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11657 int32_t scrn = sdci[3]/10000;
11658 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11659 int32_t x = sdci[5]/10000;
11660 int32_t y = sdci[6]/10000;
11661 int32_t x1 = x + xoffset;
11662 int32_t y1 = y + yoffset;
11663 int32_t rotation = sdci[7]/10000;
11664
11665 byte noclip = (sdci[8]!=0);
11666 int32_t opacity = sdci[9]/10000;
11667 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11668 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11669
11670 if(!m) //no need to log it.
11671 return;
11672
11673 if(index >= TheMaps.size())
11674 {
11675 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11676 return;
11677 }
11678
11679 const mapscr & l = *m;
11680
11681 BITMAP* b = bmp;
11682
11683 if(rotation != 0)
11684 b = script_drawing_commands.AquireSubBitmap(256, 176);
11685
11686
11687 const int32_t maxX = isOffScreen ? 512 : 256;
11688 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11689 bool transparent = opacity <= 128;
11690
11691 if(rotation != 0) // rotate
11692 {
11693 draw_map_combotype(b, l, x1, y1);
11694
11695 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11696 script_drawing_commands.ReleaseSubBitmap(b);
11697 }
11698 else
11699 {
11700 BITMAP* square = create_bitmap_ex(8,16,16);
11701 for(int32_t i(0); i < 176; ++i)
11702 {
11703 const int32_t x2 = ((i&15)<<4) + x1;
11704 const int32_t y2 = (i&0xF0) + y1;
11705
11706 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11707 {
11708 clear_to_color(square,(combobuf[l.data[i]].type));
11709 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11710 }
11711 }
11712 destroy_bitmap(square);
11713 }
11714
11715 //putscr
11716 }
11717
11718 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11719 {
11720 //sdci[1]=layer
11721 //sdci[2]=map
11722 //sdci[3]=screen
11723 //sdci[4]=layer
11724 //sdci[5]=x
11725 //sdci[6]=y
11726 //sdci[7]=rotation
11727 //[8] noclip
11728 //sdci[9]=opacity
11729
11730 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11731 int32_t scrn = sdci[3]/10000;
11732 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11733 int32_t x = sdci[5]/10000;
11734 int32_t y = sdci[6]/10000;
11735 int32_t x1 = x + xoffset;
11736 int32_t y1 = y + yoffset;
11737 int32_t rotation = sdci[7]/10000;
11738 byte noclip = (sdci[8]!=0);
11739 int32_t opacity = sdci[9]/10000;
11740
11741 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11742 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11743
11744 if(!m) //no need to log it.
11745 return;
11746
11747 if(index >= TheMaps.size())
11748 {
11749 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11750 return;
11751 }
11752
11753 const mapscr & l = *m;
11754
11755 BITMAP* b = bmp;
11756
11757 if(rotation != 0)
11758 b = script_drawing_commands.AquireSubBitmap(256, 176);
11759
11760
11761 const int32_t maxX = isOffScreen ? 512 : 256;
11762 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11763 bool transparent = opacity <= 128;
11764
11765 if(rotation != 0) // rotate
11766 {
11767 draw_map_comboiflag(b, l, x1, y1);
11768
11769 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11770 script_drawing_commands.ReleaseSubBitmap(b);
11771 }
11772 else
11773 {
11774 BITMAP* square = create_bitmap_ex(8,16,16);
11775 for(int32_t i(0); i < 176; ++i)
11776 {
11777 const int32_t x2 = ((i&15)<<4) + x1;
11778 const int32_t y2 = (i&0xF0) + y1;
11779
11780 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11781 {
11782 clear_to_color(square,(combobuf[l.data[i]].flag));
11783 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11784 }
11785 }
11786 destroy_bitmap(square);
11787 }
11788
11789 //putscr
11790 }
11791
11792
11793
11794 /////////////////////////////////////////////////////////
11795 // do primitives
11796 ////////////////////////////////////////////////////////
11797
11798 398703870 void do_primitives(BITMAP *targetBitmap, int32_t type, mapscr* theScreen, int32_t xoff, int32_t yoff)
11799 {
11800 398703870 color_map = &trans_table2;
11801
11802 //was this next variable ever used? -- DN
11803 //bool drawsubscr=false;
11804
11805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398703870 times.
398703870 if(type > 7)
11806 return;
11807
3/4
✓ Branch 0 taken 126660451 times.
✓ Branch 1 taken 272043419 times.
✓ Branch 2 taken 126660451 times.
✗ Branch 3 not taken.
398703870 if(type >= 0 && theScreen->hidescriptlayers & (1<<type))
11808 return; //Script draws hidden for this layer
11809
2/2
✓ Branch 0 taken 3206623 times.
✓ Branch 1 taken 395497247 times.
398703870 if(!script_drawing_commands.is_dirty(type))
11810 395497247 return; //No draws to this layer
11811 //--script_drawing_commands[][] reference--
11812 //[][0]: type
11813 //[][1-16]: defined by type
11814 //...
11815 //[][DRAWCMD_BMP_TARGET]: bitmap pointer
11816 //[][DRAWCMD_CURRENT_TARGET]: current render target at time command is queued? unused?
11817
11818 // Trying to match the old behavior exactly...
11819
2/2
✓ Branch 0 taken 932022 times.
✓ Branch 1 taken 2274601 times.
3206623 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
11820
11821 3206623 bool isTargetOffScreenBmp = false;
11822 3206623 const int32_t type_mul_10000 = type * 10000;
11823 3206623 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
11824 3206623 FFCore.numscriptdraws = numDrawCommandsToProcess;
11825 3206623 int32_t xoffset=xoff, yoffset=yoff;
11826
2/2
✓ Branch 0 taken 297574929 times.
✓ Branch 1 taken 3206623 times.
300781552 for(int32_t i(0); i < numDrawCommandsToProcess; ++i)
11827 {
11828
2/2
✓ Branch 0 taken 23101383 times.
✓ Branch 1 taken 274473546 times.
297574929 if(!brokenOffset)
11829 {
11830 274473546 xoffset = 0;
11831 274473546 yoffset = 0;
11832 274473546 }
11833 297574929 int32_t *sdci = &script_drawing_commands[i][0];
11834
11835
2/2
✓ Branch 0 taken 198709761 times.
✓ Branch 1 taken 98865168 times.
297574929 if(sdci[1] != type_mul_10000)
11836 198709761 continue;
11837 // get the correct render target, if set.
11838 98865168 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[DRAWCMD_CURRENT_TARGET]);
11839
11840
2/2
✓ Branch 0 taken 6429021 times.
✓ Branch 1 taken 92436147 times.
98865168 if(!bmp)
11841 {
11842 // draw to screen with subscreen offset
11843
2/2
✓ Branch 0 taken 10176922 times.
✓ Branch 1 taken 82259225 times.
92436147 if(!brokenOffset)
11844 {
11845 82259225 xoffset = xoff;
11846 82259225 yoffset = yoff;
11847 82259225 }
11848 92436147 bmp = targetBitmap;
11849 92436147 }
11850 else
11851 {
11852 //not drawing to screen, so no subscreen offset
11853
2/2
✓ Branch 0 taken 6339401 times.
✓ Branch 1 taken 89620 times.
6429021 if(brokenOffset)
11854 {
11855 89620 xoffset = 0;
11856 89620 yoffset = 0;
11857 89620 }
11858 6429021 isTargetOffScreenBmp = true;
11859 }
11860
11861
39/86
✓ Branch 0 taken 2356005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1130854 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1850 times.
✓ Branch 5 taken 2349855 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 404879 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 1535849 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2544998 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5287220 times.
✓ Branch 17 taken 21409189 times.
✓ Branch 18 taken 962949 times.
✓ Branch 19 taken 142863 times.
✓ Branch 20 taken 1530571 times.
✓ Branch 21 taken 163717 times.
✓ Branch 22 taken 9266 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 928052 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 4335769 times.
✓ Branch 30 taken 50406 times.
✓ Branch 31 taken 7971 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 148823 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 502 times.
✓ Branch 36 taken 144 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 80910 times.
✓ Branch 39 taken 59816 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 824 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 167483 times.
✓ Branch 44 taken 32636464 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✓ Branch 47 taken 855 times.
✓ Branch 48 taken 45504 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1173 times.
✓ Branch 56 taken 1092 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 1024 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 62 taken 264439 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 113329 times.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✓ Branch 71 taken 324163 times.
✓ Branch 72 taken 2790 times.
✓ Branch 73 taken 34653 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 19821648 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 6363 times.
✗ Branch 82 not taken.
✓ Branch 83 taken 906 times.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
98865168 switch(sdci[0])
11862 {
11863 case RECTR:
11864 {
11865 2356005 do_rectr(bmp, sdci, xoffset, yoffset);
11866 }
11867 2356005 break;
11868 case FRAMER:
11869 {
11870 do_framer(bmp, sdci, xoffset, yoffset);
11871 }
11872 break;
11873
11874
11875 case CIRCLER:
11876 {
11877 1130854 do_circler(bmp, sdci, xoffset, yoffset);
11878 }
11879 1130854 break;
11880
11881 case ARCR:
11882 {
11883 do_arcr(bmp, sdci, xoffset, yoffset);
11884 }
11885 break;
11886
11887 case ELLIPSER:
11888 {
11889 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
11890 }
11891 1850 break;
11892
11893 case LINER:
11894 {
11895 2349855 do_liner(bmp, sdci, xoffset, yoffset);
11896 }
11897 2349855 break;
11898
11899 case SPLINER:
11900 {
11901 do_spliner(bmp, sdci, xoffset, yoffset);
11902 }
11903 break;
11904
11905 case PUTPIXELR:
11906 {
11907 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
11908 }
11909 404879 break;
11910 case PIXELARRAYR:
11911 {
11912 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11913 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
11914 }
11915 break;
11916
11917 case TILEARRAYR:
11918 {
11919 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11920 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
11921 }
11922 break;
11923
11924 case LINESARRAY:
11925 {
11926 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11927 do_linesr(bmp, i, sdci, xoffset, yoffset);
11928 }
11929 break;
11930
11931 case COMBOARRAYR:
11932 {
11933 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11934 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
11935 }
11936 break;
11937
11938
11939
11940 case DRAWTILER:
11941 {
11942 1535849 do_drawtiler(bmp, sdci, xoffset, yoffset);
11943 }
11944 1535849 break;
11945
11946 case DRAWTILECLOAKEDR:
11947 {
11948 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
11949 }
11950 break;
11951
11952 case DRAWCOMBOR:
11953 {
11954 2544998 do_drawcombor(bmp, sdci, xoffset, yoffset);
11955 }
11956 2544998 break;
11957
11958 case DRAWCOMBOCLOAKEDR:
11959 {
11960 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
11961 }
11962 break;
11963
11964 case FASTTILER:
11965 {
11966 5287220 do_fasttiler(bmp, sdci, xoffset, yoffset);
11967 }
11968 5287220 break;
11969
11970 case FASTCOMBOR:
11971 {
11972 21409189 do_fastcombor(bmp, sdci, xoffset, yoffset);
11973 }
11974 21409189 break;
11975
11976 case DRAWCHARR:
11977 {
11978 962949 do_drawcharr(bmp, sdci, xoffset, yoffset);
11979 }
11980 962949 break;
11981
11982 case DRAWINTR:
11983 {
11984 142863 do_drawintr(bmp, sdci, xoffset, yoffset);
11985 }
11986 142863 break;
11987
11988 case DRAWSTRINGR:
11989 {
11990 1530571 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
11991 }
11992 1530571 break;
11993
11994 case DRAWSTRINGR2:
11995 {
11996 163717 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
11997 }
11998 163717 break;
11999
12000 case QUADR:
12001 {
12002 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
12003 }
12004 9266 break;
12005
12006 case QUAD3DR:
12007 {
12008 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
12009 }
12010 break;
12011
12012 case TRIANGLER:
12013 {
12014 do_drawtriangler(bmp, sdci, xoffset, yoffset);
12015 }
12016 break;
12017
12018 case TRIANGLE3DR:
12019 {
12020 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
12021 }
12022 break;
12023
12024 case POLYGONR:
12025 {
12026 do_polygonr(bmp, i, sdci, xoffset, yoffset);
12027 }
12028 break;
12029
12030
12031 case BITMAPR:
12032 {
12033 928052 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
12034 }
12035 928052 break;
12036
12037 case BITMAPEXR:
12038 {
12039 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
12040 }
12041 break;
12042
12043 case DRAWLAYERR:
12044 {
12045 4335769 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12046 }
12047 4335769 break;
12048
12049 case DRAWSCREENR:
12050 {
12051 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12052 }
12053 50406 break;
12054
12055 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
12056 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
12057 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
12058 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
12059 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
12060 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
12061 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
12062 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
12063 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
12064 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
12065 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
12066 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
12067 167483 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
12068 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
12069 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
12070 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
12071 855 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
12072 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
12073 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
12074 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
12075
12076 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
12077 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
12078 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
12079 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
12080 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12081 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12082 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12083 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12084 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12085 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12086 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12087 264439 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
12088 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
12089 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
12090 case TILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, false, "TileBlit()"); break;
12091 case COMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, false); break;
12092 case BMPTILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, true, "TileBlit()"); break;
12093 case BMPCOMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, true); break;
12094 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
12095 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
12096 324163 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
12097 2790 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
12098 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
12099
12100 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12101 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12102 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12103 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12104 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12105 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
12106 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
12107 6363 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
12108 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
12109 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
12110 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
12111 }
12112 98865168 }
12113
12114
12115 3206623 color_map=&trans_table;
12116 398703870 }
12117
12118 16080972 void CScriptDrawingCommands::Clear()
12119 {
12120 16080972 scb.update();
12121 16080972 dirty_layers.clear();
12122
2/2
✓ Branch 0 taken 11450949 times.
✓ Branch 1 taken 4630023 times.
16080972 if(commands.empty())
12123 11450949 return;
12124
12125 //only clear what was used.
12126 4630023 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12127 4630023 count = 0;
12128
12129 4630023 draw_container.Clear();
12130 16080972 }
12131 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
12132 {
12133 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
12134 if(commands.empty())
12135 return ret;
12136 ret->push_commands(this, false);
12137
12138 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12139 count = 0;
12140
12141 draw_container.Clear();
12142 return ret;
12143 }
12144 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
12145 {
12146 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
12147 count += other->count;
12148 if(del) delete other;
12149 }
12150
12151 148956 void do_script_draws(BITMAP *targetBitmap, mapscr* theScreen, int32_t xoff, int32_t yoff, bool hideLayer7)
12152 {
12153
2/2
✓ Branch 0 taken 147962 times.
✓ Branch 1 taken 994 times.
148956 if(XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
12154
2/2
✓ Branch 0 taken 147138 times.
✓ Branch 1 taken 1818 times.
148956 if(XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
12155 148956 do_primitives(targetBitmap, 0, theScreen, xoff, yoff);
12156 148956 do_primitives(targetBitmap, 1, theScreen, xoff, yoff);
12157
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 147962 times.
148956 if(!XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
12158
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 147138 times.
148956 if(!XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
12159 148956 do_primitives(targetBitmap, 4, theScreen, xoff, yoff);
12160 148956 do_primitives(targetBitmap, 5, theScreen, xoff, yoff);
12161 148956 do_primitives(targetBitmap, 6, theScreen, xoff, yoff);
12162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148956 times.
148956 if(!hideLayer7) do_primitives(targetBitmap, 7, theScreen, xoff, yoff);
12163 148956 }
12164